我想允許用戶選擇一行,並給定該朋友的關係,在點擊行時發生不同的操作。例如,如果朋友,然後聊天打開,如果不是朋友,則可以允許發送朋友請求,等等。允許對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