English 中文(简体)
缩略语
原标题:NSMutableArray addObject doesn t seem to work
  • 时间:2012-05-02 06:19:51
  •  标签:
  • ios
  • arrays

我确实是新的SOS发展,我是试图形成简单表格观点的Im,因此,我增加了一个表象主计长,把我的习惯类别加到这里,现在我正试图增加项目。

So I created a new array:

@property (nonatomic, strong) NSMutableArray *activity;

And I the viewDidLoad, I tried adding some items to the array:

for(int i = 0; i < 20; i++) 
{
    NSLog(@"Current item: %u", i);
    Item *item = [[Item alloc] init];
    item.time = @"14:30";
    item.text = @"A simple test";
    item.startedAgo = @"yesterday";
    item.project = @"testProject";
    [self.activity addObject:item];
}

NSLog(@"Activity count: %u", [self.activity count]);

当我试图生产阵列的透镜时,该标志似乎被罚款,其停留时间为0。

2012-05-02 14:12:50.772 coop_dev[15352:f803] Current item: 0

......

2012-05-02 14:12:50.783 coop_dev[15352:f803] 经常项目:19

2012-05-02 14:12:50.784 coop_dev[15352:f803] 活动:0

我在这里找不到什么东西?

最佳回答

Have you initialize your activity array before adding object to it??
In viewDidLoad initialize your activity array as follows :-

self.activity = [[[NSMutableArray alloc]init]autorelease];
问题回答

确保在使用之前先开始使用你的阵列

self.activity = [[NSMutableArray alloc] init];

如果你使用ARC,就不需要自动释放。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签