PerformSegueWithIdentifier 无法始终如一地工作
PerformSegueWithIdentifier not working consistently
我没有在我的项目中使用任何导航控制器。这个项目是网上拿的,是Swift的侧边栏菜单。在侧边栏菜单中,有一个 table 视图,每行将 performSegueWithIdentifier
.
问题:
tableViewCell 的前几次点击非常有效,只需单击一下即可关闭菜单。但是之后,需要双击 tableViewCell 才能关闭菜单。
需要单击两次才能关闭菜单:(第一次单击 tableViewCell,viewController 将消失,第二次单击 tableViewCell 将关闭菜单)
NavigationViewController(侧边栏菜单)
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.snapshot.removeFromSuperview()
var segueName: NSString = "";
if (indexPath.row == 0) {
print("ROW 1")
segueName = "listview"
}
if (indexPath.row == 1) {
print("CLICK ROW 2")
segueName = "othernav"
}
self.performSegueWithIdentifier(segueName as String, sender: self)
}
故事板
资源取自here。
试试:
dispatch_async(dispatch_get_main_queue(), {});
这里有一些关于 "bug" 的信息。但我认为 Apple 修复了它...
http://openradar.appspot.com/19563577
您的代码应如下所示:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.snapshot.removeFromSuperview()
var segueName: NSString = "";
if (indexPath.row == 0) {
print("ROW 1")
segueName = "listview"
}
if (indexPath.row == 1) {
print("CLICK ROW 2")
segueName = "othernav"
}
dispatch_async(dispatch_get_main_queue(), {});
self.performSegueWithIdentifier(segueName as String, sender: self)
}
如果这不起作用,您可以试试这个:
替换
dispatch_async(dispatch_get_main_queue(), {});
self.performSegueWithIdentifier(segueName as String, sender: self)
与:
NSOperationQueue.mainQueue().addOperationWithBlock {
self.performSegueWithIdentifier(segueName as String, sender: self) }
我没有在我的项目中使用任何导航控制器。这个项目是网上拿的,是Swift的侧边栏菜单。在侧边栏菜单中,有一个 table 视图,每行将 performSegueWithIdentifier
.
问题:
tableViewCell 的前几次点击非常有效,只需单击一下即可关闭菜单。但是之后,需要双击 tableViewCell 才能关闭菜单。
需要单击两次才能关闭菜单:(第一次单击 tableViewCell,viewController 将消失,第二次单击 tableViewCell 将关闭菜单)
NavigationViewController(侧边栏菜单)
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.snapshot.removeFromSuperview()
var segueName: NSString = "";
if (indexPath.row == 0) {
print("ROW 1")
segueName = "listview"
}
if (indexPath.row == 1) {
print("CLICK ROW 2")
segueName = "othernav"
}
self.performSegueWithIdentifier(segueName as String, sender: self)
}
故事板
资源取自here。
试试:
dispatch_async(dispatch_get_main_queue(), {});
这里有一些关于 "bug" 的信息。但我认为 Apple 修复了它...
http://openradar.appspot.com/19563577
您的代码应如下所示:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.snapshot.removeFromSuperview()
var segueName: NSString = "";
if (indexPath.row == 0) {
print("ROW 1")
segueName = "listview"
}
if (indexPath.row == 1) {
print("CLICK ROW 2")
segueName = "othernav"
}
dispatch_async(dispatch_get_main_queue(), {});
self.performSegueWithIdentifier(segueName as String, sender: self)
}
如果这不起作用,您可以试试这个:
替换
dispatch_async(dispatch_get_main_queue(), {});
self.performSegueWithIdentifier(segueName as String, sender: self)
与:
NSOperationQueue.mainQueue().addOperationWithBlock {
self.performSegueWithIdentifier(segueName as String, sender: self) }