User1238 User1238 - 1 year ago 108
iOS Question

Customize TableViewCell with swift

I am trying to add subtitle to cells in a table view. I am trying this code but the subtitle is not showing.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell=tableView.dequeueReusableCellWithIdentifier("topCell", forIndexPath: indexPath) as UITableViewCell
var personImage=UIImage(named: listPerson[indexPath.row].country)

return cell

I also want to know if it's possible to add another image in the right of the cell.

Answer Source

To display the text in detailTextLabel you have to set the style of the cell in the Attributes Inspector of Interface Builder (⌥⌘4)to Subtitle.

To add a custom image on the right edge you can create the UIImageView instance programmatically and add it as subview to the accessory view.

However it might be more suitable to use a custom cell class providing an outlet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download