zoukankan      html  css  js  c++  java
  • 【原】NSMutableArray的alloc、init方法与array的区别疑问

    在项目中的这个函数里面,[NSMutableArray array]与[[NSMutableArray alloc] init];有着较明显的区别

    同样是建立一个NSMutableArray临时变量,为什么前者可以,后者在多次调用clearLastLine函数时会出错呢?

    亟待解决!在TryIt.proj->FingerPaintView里面

    - (void)clearLastLine {
        NSMutableArray *lastLine = [NSMutableArray array];
        if ([mDrawLines count] >= 1)
        {
            lastLine = [mDrawLines objectAtIndex:[mDrawLines count]-1];
            [mRemovedLines addObject:lastLine];
            [mDrawLines removeLastObject];
            NSLog(@"%s:removed lines:%@",__FUNCTION__,mRemovedLines);
            mCurrentLine = nil;
            [self setNeedsDisplay];//系统会调用drawRect绘图
        }
    }

    /////////////////

    - (void)clearLastLine {
        NSMutableArray *lastLine = [[NSMutableArray alloc] init];
        if ([mDrawLines count] >= 1)
        {
            lastLine = [mDrawLines objectAtIndex:[mDrawLines count]-1];
            [mRemovedLines addObject:lastLine];

       [lastLine release];
            [mDrawLines removeLastObject];
            NSLog(@"%s:removed lines:%@",__FUNCTION__,mRemovedLines);
            mCurrentLine = nil;
            [self setNeedsDisplay];//系统会调用drawRect绘图
        }
    }

  • 相关阅读:
    iOS- static extern const
    App 性能分析
    迭代器和生成器
    软件工程之个人软件开发----起步
    myeclipse调式与属性显示
    hdu 6188
    uva10780 质因子分解
    云服务器端口号的几个操作
    Redis错误 : MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.
    ubuntu系统安装宝塔面板Linux版
  • 原文地址:https://www.cnblogs.com/wengzilin/p/2411754.html
Copyright © 2011-2022 走看看