Reputation: 93
Hi I need to call the cell label outside of the cellForRowAt indexPath
function but it show the error any one help me to solve this issues
here is my code:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell: FeedCell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell
cell.slider.addTarget(self, action: #selector(handleVideoChageSlider), for:.valueChanged)
cell.slider.tag = indexPath.row
cell.videolabl.text="check"
return cell
}
@IBAction func GetUpdatesButtonTouched(_ sender: AnyObject) {
//how do i call the cell fuction
//cell.slider.addTarget(self, action: #selector(handleVideoChageSlider), for:.valueChanged )
}
I need to call this cell.label
to inside of the fuction of:
@IBAction func handleVideoChageSlider(_ sender: UISlider) {
print(sender.value)
//like cell.videolabel.text="change name"
}
Thanks in advance
Upvotes: 0
Views: 6585
Reputation: 1
I've not checked all answers instead ,I tried. Not all worked due to not getting indexpath,
In this case with swift 5,Xcode 10.3 one thing worked for me. Let me know if something wrong, Thankyou.
let cell: cellCarerDailySchedual = tblDailySchedual.cellForRow(at: NSIndexPath(row: sender.tag, section: 0) as IndexPath) as! cellCarerDailySchedual
Upvotes: 0
Reputation: 46
You can use below code to get the cell content:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: FeedCell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell
cell.slider.addTarget(self, action: #selector(handleVideoChageSlider), for:.valueChanged)
cell.slider.tag = indexPath.row
cell.videolabl.text="check"
return cell
}
@IBAction func handleVideoChageSlider(_ sender: UISlider) {
print(sender.value)
//tableView is your table view object
let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: sender.tag, inSection: 0)) as! FeedCell
//now you can get your label
cell.Yourlabel.text = "Hello India"
}
Upvotes: 2
Reputation: 1290
You need to make a cell in the function as below:
@IBAction func handleVideoChageSlider(_ sender: UISlider) {
print(sender.value)
let cell: FeedCell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: sender.tag, inSection: 0)) as! FeedCell
cell.videolabl.text="change name"
}
Upvotes: 1
Reputation: 1456
To access Cell Content
Please assign indexPath with section no as well item No.
let index = NSIndexPath(forItem: 0, inSection: 0)
let refCell = tblListingURL.cellForRowAtIndexPath(index) as! FeedCell
refCell.videolabl.text = "NewText"
Upvotes: 2
Reputation: 1824
You can access your cell content outside the function like this :
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as! FeedCell
print(currentCell.videoLabel.text)
Upvotes: 0