My NSMutableArray lOfSegments, declared as IVAR, get populated correctly. During the debug it shows 4 object in the array.
for (int x=0; [arrayOfSegmentsTcIn count]>x; x++) {
NSDictionary *segmentDic=[[NSDictionary alloc] initWithObjectsAndKeys: [arrayOfSegmentsNumbers objectAtIndex:x],@"segment",[arrayOfSegmentsTcIn objectAtIndex:x],@"tc_in",[arrayOfSegmentsTcOut objectAtIndex:x],@"tc_out", nil];
[lOfSegments addObject:segmentDic];
[myDMXML.segments addObject:segmentDic];
}
[self.xmlTCLable setStringValue:[myDMXML startTimeCode]];
[self.xmlDurationLable setStringValue:[myDMXML duration]];
[self xmlValidationCheck];
NSLog(@"arrayController:%@",[lOfSegments valueForKey:@"segment"]);
[self.tableViewOutlet reloadData];
NSLog list the array correctly but when reloadData is executed the code jumps to
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [lOfSegments count];
}
The array is null.
The Object is initialised in viewDidLoad as
lOfSegments = [[NSMutableArray alloc]init];
Please Help!
First, I recommend making your code more clear here by using self.lOfSegments
rather than directly accessing an ivar. (The fact that the ivar lacks a leading _
is very suspicious as well, and raises the question of whether this is even the variable you think it is.)
On the assumption that this is the variable you think it is, and that you have overridden the standard behavior to make the ivar match the property or created explicit ivars (neither of which you should do), there are several common causes for this kind of problem:
viewDidLoad
and then viewDidLoad
blew away the array. Many things can run prior to viewDidLoad
, and viewDidLoad
can run more than once (at least this used to be true; I'd have to study whether the view-loading changes in iOS 6 made it guaranteed to be run once.) lOfSegments
between the time your initialization code ran and the time reloadData
ran. If you would reliably use self.
then you could override setLOfSegments:
so you could log this. Or you could mark this property readonly so you could prevent it. Thats one of many reasons that you should use properties, not ivars. reloadData
. Ensure that the log statement actually printed prior to getting to reloadData
and is on the same queue (the queue identifier will be part of the NSLog
output in brackets). I don't think this is likely given your description, but it is a common problem. reloadData
. This is a more common mistake then you may think. Log self
and make sure the memory address is the same in both cases. looks like you have variable with same name lOfSegments
in method viewDidLoad
. So in viewDidLoad
you use stack variable, in numberOfRowsInTableView
- instance variable.
Or maybe tableViewOutlete.dataSource
pointing on different viewController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.