Gaurang Bham
Gaurang Bham

Reputation: 31

I would like to add a second column to my uitableview. How?

I currently have a table view with one column and static information. I would like to add a second column with information that will updated from a server.

Here is my code right now:

var array = ["Daskalakis Athletic Center" , "Hagerty Library", "Hans Dining Hall", "Northside Dining Hall", "Urban Eatery", "Creese Student Center", "Cyber Learning Center", "Rush Advisors"]

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return array.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell: UITableViewCell! = self.ListView
        .dequeueReusableCellWithIdentifier("cell") as UITableViewCell!

    cell.textLabel!.text = self.array[indexPath.row]

    return cell
}

Upvotes: 0

Views: 54

Answers (2)

Faran Rasheed
Faran Rasheed

Reputation: 93

As Eugene suggested, you may need to rewrite the implementation and need to use UICOllectionView instead of UITableView.

An alternate approach is, you design the cell in such a way that it looks like it have two coloumns (Reduce the cell content view width to half and replicate the same view and align it to other half, you can also add a vertical separator in between both).

Upvotes: 1

Eugene Zaychenko
Eugene Zaychenko

Reputation: 319

You may use UICollectionView instead UITableView. Or you can use second UITableView.

Upvotes: 0

Related Questions