in the method below why indexPath.Row always return 0???
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
[cell.textLabel setText:[mainItems objectAtIndex:indexPath.row]];
return cell;
}
mainItems is a NSMutableArray and has 5 items (“item 1”, “item 2”,…) the View does get 5 items… but they are all “Item 1” and NOT item 1, item 2…
what am i doing wrong?
My guess is that you’re returning the wrong value in your implementation of
-numberOfSectionsInTableView, and the table view is asking you for the 0th row of 5 sections.Table views have sections, and each section has rows. Many table views only have one section, but many rows in that section. It sounds like you have one section, with 5 rows. Be sure that you return the correct values in each of: