我有一个 UITableView,我用 NSMutable 数组中的对象填充。出于某种原因,表格视图总是加载数组 - 1 对象。如果 [array count] == 3 它只加载 2 个对象(单元格)
这是我的代码。谁能告诉我为什么 tableview 总是跳过数组中的第一个或最后一个对象?(我不知道是哪个)
- (void)viewDidLoad
{
[super viewDidLoad];
// singleton class containing NSMutable array
sharedEventData = [EventData sharedDataInstance];
self.navigationController.delegate = self;
// if this returns 10 the tableview always loads 9 objects. count -1
NSLog(@"eventList count: %u", [sharedEventData.listOfEvents count]);
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
// sharedEventData.listOfEvents is my NSMutableArray
return [sharedEventData.listOfEvents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
EKEvent *currentEvent = [sharedEventData.listOfEvents objectAtIndex:indexPath.row];
NSDate *date = [currentEvent startDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSString *dateString = [dateFormatter stringFromDate:date];
// Get the event at the row selected and display it's title
cell.textLabel.text = [[sharedEventData.listOfEvents objectAtIndex:indexPath.row] title];
cell.detailTextLabel.text = dateString;
//NSLog(@"date string: %@", dateString);
return cell;
}