CodeMilian
CodeMilian

Reputation: 1290

Multiple rows inside table view cell for tableview

I have an array of objects that I would like to display information of inside a table view. I am trying to find some good examples on the web on how to display multiple columns per row or at least give the impression of multiple columns.

For example.

Object Person -FirstName -LastName

My array has a collection of multiple person objects.

I want to display the data as such:

John Smith

Jane Doh

Don Johnson

Marco Polo

So far I have this

-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];

    if(cell==nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];
    }

    Person *Item = [self.Data objectAtIndex:indexPath.row];


    cell.textLabel.text = Item.FirstName;

    //Add the rest of the properties as separate columns

    return cell;


}

What is the best approach for this?

Upvotes: 0

Views: 1206

Answers (1)

Saurav Nagpal
Saurav Nagpal

Reputation: 1267

For column behavior you can add label on your cell and display the text on label.

cell.label1.text = Item.FirstName;
cell.label2.text = Item.LastName;
cell.label3.text = Item.City;

Design the cell according to your requirement and provide a frame to label as it looks like column in table view :)

Upvotes: 1

Related Questions