# Change what is displayed in cell for row in tableview cell

**URL:** <https://forums.kodeco.com/t/change-what-is-displayed-in-cell-for-row-in-tableview-cell/72697>\
**Category:** Swift\
**Created:** [June 2, 2019, 6:43pm UTC](https://forums.kodeco.com/t/change-what-is-displayed-in-cell-for-row-in-tableview-cell/72697 "2019-06-02T18:43:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [June 2, 2019, 6:43pm UTC](https://forums.kodeco.com/t/change-what-is-displayed-in-cell-for-row-in-tableview-cell/72697/1 "2019-06-02T18:43:56Z")

</div>

I want to hit a button and change what is printed in a tableview cell after view did load. When my code loads 5 items are printed in each tableview cell. I want to hit a button and when hit it should only print 2 attributes and change what is printed before the attribute. The attributes come from core data.

```
                  var set = 0 

```

@objc func l1UPBTN(sender: UIButton){  
set == 1  
theScores.reloadData()  
}

func tableView(\_ tableView: UITableView, cellForRowAt indexPath: IndexPath) → UITableViewCell {  
let title = itemName[indexPath.row]  
let cell = theScores.dequeueReusableCell(withIdentifier: “MyCell”, for : indexPath)  
cell.textLabel!.numberOfLines = 2  
cell.selectionStyle = .default

```
if set == 1 {
    let attr1 = title.value(forKey: "atBATS") as? String
    let attr5 = title.value(forKey: "positon") as? String
    let text = [attr1," eeeee :"," we :",attr5].flatMap { $0 }.reduce("", +)
    cell.textLabel?.text = "\(text)"
    cell.textLabel?.textAlignment = .center
    cell.layoutMargins = UIEdgeInsets.zero
}

if set == 0 {
    let attr1 = title.value(forKey: "atBATS") as? String
    let attr3 = title.value(forKey: "age") as? String
    let attr4 = title.value(forKey: "weight") as? String
    let attr2 = title.value(forKey: "hits") as? String
    let attr5 = title.value(forKey: "positon") as? String
    let text = [attr1," Weight :",attr3,"\n","Height : ",attr2," Age : ",attr4," Position :",attr5].flatMap { $0 }.reduce("", +)
    cell.textLabel?.text = "\(text)"
}

cell.textLabel?.textAlignment = .center
cell.layoutMargins = UIEdgeInsets.zero
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero

return cell

```

}

---

<div class="post-metadata">

**Author:** ![sgerrard](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sgerrard/32/93812_2.png) [@sgerrard](https://forums.kodeco.com/u/sgerrard)\
**Post date:** [June 3, 2019, 2:20am UTC](https://forums.kodeco.com/t/change-what-is-displayed-in-cell-for-row-in-tableview-cell/72697/2 "2019-06-03T02:20:30Z")

</div>

> [@timswift](#):
>
> @objc func l1UPBTN(sender: UIButton){  
> set == 1

Isn’t that supposed to be **set = 1**?

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [November 16, 2019, 10:43am UTC](https://forums.kodeco.com/t/change-what-is-displayed-in-cell-for-row-in-tableview-cell/72697/3 "2019-11-16T10:43:58Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
