views:

73

answers:

2

I have an uitableview with UITableViewCellSTyleValue1 so i have a textlabel and a detail text label.

The second thing i've got is a NSMutableArray. Now i want to fill the textLabels with the even items and the detailTextlabels with the odd entries.

So for example cell one(zero) gets entry 0 and 1 cell one gets 2 and 3 and so on.

I didn't get it working until now. :(

+1  A: 

That must be pretty easy to do (if you have problems only with distributing array items between corresponding cell labels)... As every cell "consumes" 2 array entry - number of cells equals [dataArray count]/2:

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

Then in your cellForRowAtIndexPath implementation:

...
cell.textLabel.text = [dataArray objectAtIndex:2*indexPath.row];
cell.detailTextLabel.text = [dataArray objectAtIndex:2*indexPath.row + 1];
...
Vladimir
great Thanks a lot!
A: 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// the usual cell creation/reuse stuff..

// obtain Label1, 2 by viewWithTag.. 

// index is your instance variable..

    index = indexPath.row * 2;

    Label1.text = [myArr objectAtIndex:index];
    Label2.text = [myArr objectAtIndex:index + 1];

}
Prakash
of course thank you,too!