【发布时间】:2015-07-02 06:05:24
【问题描述】:
tableviewcell 的每个单元格中都有一个按钮。单击按钮时,在单元格编码页面中,我有一个已经在工作的操作。但是我决定让用户在动作开始之前确认它,所以在动作中添加了一个UIAlertController。警报控制器在 UIviewcontroller 中工作正常,但在带有以下代码的 UItableviewcell 中,我收到错误消息:“没有名为 presentviewcontroller 的成员”。我怎样才能让它工作?我的代码在这里。谢谢
@IBAction func followBtn_click(sender: AnyObject) {
if title == "Following" {
var refreshAlert = UIAlertController(title: "Sure?", message: "Do you want to unfollow this person?", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
var query = PFQuery(className: "follow")
query.whereKey("user", equalTo: PFUser.currentUser()!.username!)
query.whereKey("userToFollow", equalTo: usernameLbl.text!)
var objects = query.findObjects()
for object in objects! {
object.delete()
}
}))
refreshAlert.addAction(UIAlertAction(title: "No", style: .Default, handler: { (action: UIAlertAction!) in
println("Cancel unfollow")
}))
self.presentViewController(refreshAlert, animated: true, completion: nil)
/* self.window?.rootViewController?.presentViewController(refreshAlert, animated: true, completion: nil)
when I use the above to make it run, the code runs but nothing happens and I get the warning below in the output area
2015-07-02 08:57:22.978 MyLast[968:200872] Warning: Attempt to present <UIAlertController: 0x7f849c04ed20> on <UINavigationController: 0x7f8499c69020> whose view is not in the window hierarchy!
*/
}
else {
println(“rest will work”)
/* rest of the code */
}
}
【问题讨论】:
标签: ios swift uialertcontroller tableviewcell