1

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

1
  • WARNING : you're leaking memory. After 'AssessObject *newObj1 = [[AssessObject alloc] init];' , you should call [newObj1 release] before pointing to a new value. You could also initiate 'newObj1' at nil... Commented Nov 25, 2011 at 16:52

1 Answer 1

3
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that. Should it just work when changing that? As it still shows only one result in my tabel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.