开发者

NSArray ObjectAtIndex:0 --- get count?

I have an NSArray that I pass in through a delegate method:

- (void)didFinishParsing:(NSArray *)array {开发者_如何学运维
    [self.myArray addObjectsFromArray:array];
    NSLog(@"%@", self.myArray);
    [self.tableView reloadData];
}

There's only one object in the array and I'd like the tableView row count to equal the amount of objects in the array objectAtIndex:0, but I cannot get the count. I have tried:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[self.myArray objextAtIndex:0] count];
}

How do I get the number of object inside the first (and only) object in my array?


To count the array at index 0 of self.myArray your syntax is correct. Is your array variable setup how you think it is?

The method call addObjectsFromArray: will add the contents of array to the end of self.myArray.

So in other words: [array objectAtIndex:0] will become [self.myArray lastObject:]

If you're having trouble running count: on [self.myArray objectAtIndex:0] or [self.myArray lastObject] then the object you're trying to count might be nil, empty, not an NSArray/Set as you are expecting it to be.


If you're trying to create an array within an array you should instead use

[self.myArray addObject: array];

This will add the array at the next index inside self.myArray. What you were doing previously with

[self.myArray addObjectsFromArray:array];

was adding the contents of array into self.myArray not adding array itself into self.myArray.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜