Reputation: 2669
I've got the following code. The array is built up from XML, so each node has a Title (which will be the section title) and text (which will go in the cell itself)
So each node has 1 cell and 1 title
- (NSInteger)
numberOfSectionsInTableView:(UITableView *)tableView {
return [arrySummaryTitle count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
AssessObject *newObj1 = [[AssessObject alloc] init];
newObj1=[totalArray objectAtIndex:indexPath.row];
cell.textLabel.text = newObj1.routeImage;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [arrySummaryTitle objectAtIndex:section];
}
What i'm really struggling to do is loop through the cell and section title to loop through the newObj1.routeImage and have cell text and cell section from one array? I'm even struggling to explain it haha
The array is built up like:
Section Title, Section Title, Section Title etc
The same for the text, and they're both in newObj1.whatever
So I need it so the table is built up like:
[Section Header]
[Section Text]
[Section Header]
[Section Text]
etc
Make sense?! Tom
Upvotes: 1
Views: 845
Reputation: 3927
newObj1 = [totalArray objectAtIndex:indexPath.section];
This will get the section instead of the row since there is only one item in each section and indexPath.row
will always return the same value. Refer to NSIndexPath UIKit Additions.
Upvotes: 3