Programmatically emulate the selection in UITableViewController in Swift

后端 未结 2 1495
礼貌的吻别
礼貌的吻别 2020-12-25 09:32

Sorry for the question without any line of code. I need advice how to proceed, if at possible that I want.

In Swift language.

Let us assume there is an app

2条回答
  •  一个人的身影
    2020-12-25 10:06

    You can also do this simply by accessing the tableView delegate to force didSelectRowAtIndexPath to fire.

    Programatically select a row to work with:

    self.tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.Top)
    

    Programatically selecting row does not fire the "didSelectRowAtIndexPath" function so we must manually force the firing as per below:

    self.tableView.delegate!.tableView!(tableView, didSelectRowAtIndexPath: indexPath!)
    

    Objective-C:

    [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:path];
    

提交回复
热议问题