【发布时间】:2017-10-24 16:36:00
【问题描述】:
我的表格视图单元格中有一个关注按钮,当我点击它时,我通过将我的用户 ID 和他的用户 ID 发送到 api 路由来关注用户。
var fbFriends = [People]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: FBFriendsTableViewCell = tableView.dequeueReusableCell(withIdentifier: "fbFriendsCell", for: indexPath) as! FBFriendsTableViewCell
cell.friendFollowButton.addTarget(self, action: #selector(followButtonTapped(_:)), for: .touchUpInside)
return cell
}
@objc func followButtonTapped(_ sender: UIButton) {
user.followUser(token: Helper.shared.getAccessToken()!, userId: Helper.shared.retriveUserID()!, followeeId: fbFriendsData[indexPath.row].userId) { (status, code, err, msg, body) in
//Do something with response
}
}
我需要的是发送我将在选择器参数中关注的用户的 ID,这样我就可以在 followUser 函数中使用它,而不是已经在 tableView 闭包之外的 indexPath.row。所以我需要的是这样的东西。
@objc func followButtonTapped(_ sender: UIButton, _ rowIndex: Int) {
user.followUser(token: Helper.shared.getAccessToken()!, userId: Helper.shared.retriveUserID()!, followeeId: fbFriendsData[rowIndex].userId) { (status, code, err, msg, body) in
//Do something with the response
}
}
【问题讨论】:
标签: swift function uitableview arguments selector