0

I have a NSMutableArray and a grouped tableview that I populate from NSMutableArray.

When I print NSmutableArray with NSLog Output is "String1","String2","String3"

But on UITableView Cell I always see the first item of NSMUtableArray:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return [_presenterList count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSLog(@"_presenterList objectAtIndex: %@",[_presenterList objectAtIndex:indexPath.row]);

    cell.textLabel.text=[_presenterList objectAtIndex:indexPath.row];
return cell;
}

output NSlog "String1"

Output on tableview

String1
String1
String1

What am I doing wrong?

EDIT SCREEN SHOT ADDED

I create some headers from Strings and 1 tableview row like in the picture

enter image description here

2 Answers 2

2
cell.textLabel.text=[_presenterList objectAtIndex:indexPath.section];

instead of cell.textLabel.text=[_presenterList objectAtIndex:indexPath.row];

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

Comments

1

You are returning "1" in numberOfRowsInSection and [array count] in numberOfSectionsInTableView. This is backwards (unless you really want a section for every item in the array.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_presenterList count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

3 Comments

If you are going to post this update to tableView:numberOfRowsInSection: you should also post the required update to numberOfSectionsInTableView:.
@NSPostWhenIdle I need exactly one row and section count that is equal to NSMutableArray Count plse see the screen shot on edited question , So your answer gives me 1 section and rows equal to NSmutablecount that is exact opposite of what I need
@MordFustang If this is the design you really want to go with take a look at the answer below.

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.