我想允许用户选择一行,并给定该朋友的关系,在点击行时发生不同的操作。例如,如果朋友,然后聊天打开,如果不是朋友,则可以允许发送朋友请求,等等。允许对tableview行进行条件操作select
目前,我已经实现了以下,但在每一行的点击,无论朋友的状态与否,聊天打开并抛出一个错误所产生的IndividualChatController
的friendChat
对象:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
// Ensure controller knows which dataset to pull from,
// so detail view is correct
let friendChat: Friend
if searchController.active && searchController.searchBar.text != "" {
friendChat = filterMappedFriends[indexPath.row]
} else {
friendChat = mappedFriends[indexPath.row]
}
// Now set the conditional cases: if a friend then chat, if user then friend request if not user then can invite them:
if(friendChat.statusSort == 2) {
performSegueWithIdentifier("showIndividualChat", sender: self)
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showIndividualChat" {
let controller = segue.destinationViewController as! IndividualChatController
controller.friendChat = friendChat
controller.senderId = FeastGlobal.sharedInstance.userID
controller.senderDisplayName = FeastGlobal.sharedInstance.userName
}
}
} else if (friendChat.statusSort == 1) {
print("Can invite to be friend")
} else if (friendChat.statusSort == 0) {
print("Invite to Feast")
}
}
主营:
近拍的SEGUE名称:
如果我执行你的代码,其他操作假定使用'Segue'的,再扔错误。你的回答是不完整的 – Sauron
这个答案是正确的。当你调用'performSegueWithIdentifier'时,你应该传递'friendChat'作为'sender',这样你就可以在'prepareForSegue'中访问它。确保你没有从表格视图单元的'action'到故事板中的下一个视图控制器的链接 – Paulw11
我在那里发表评论,告诉你把你的东西放在那里。我的答案是完整的,无论您是否希望我在其中复制和粘贴其余代码。 编辑:这里让我走得更远。 – Jay