Ios PrepareForSegue未执行

Ios PrepareForSegue未执行,ios,swift,segue,Ios,Swift,Segue,我已经进行了非常彻底的检查,我浏览了许多类似的SO线程,但我似乎仍然不明白为什么PrepareForSegue没有在应该执行的时候执行。我已经在其他几家风投中实现了它,这次我看不出有什么不同 预处理函数 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if (segue.identifier == "viewProfile") { let vc =

我已经进行了非常彻底的检查,我浏览了许多类似的SO线程,但我似乎仍然不明白为什么PrepareForSegue没有在应该执行的时候执行。我已经在其他几家风投中实现了它,这次我看不出有什么不同

预处理函数

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "viewProfile") {
            let vc = segue.destinationViewController as! ProfileController
            let x = sender as! UITapGestureRecognizer
            let location = x.locationInView(self.myBountiesTableView) as CGPoint
            let indexPath = self.myBountiesTableView.indexPathForRowAtPoint(location) as NSIndexPath?
            let cell = self.myBountiesTableView.cellForRowAtIndexPath(indexPath!) as! BountyCellNew
            vc.userId = cell.bounty.bountyCreatedById!.description
        }
    }
prepareForSegue应从以下位置解雇的VC:MyBountiesVC

我检查过的东西:VC类设置为MyBountiesVC。segue标识符设置为viewProfile


点击连接有UIAPgestureRecognitor的UIImageView时,应触发segue。我在另一个VC中完成了类似的实现,效果很好。

请确保您正在点击手势识别器中调用
performsguewithidentifier:sender:
方法。一、 就个人而言,我更愿意在UIButton上添加图像,然后将该按钮的操作处理程序连接到我想在点击图像时加载的视图控制器。

正如vacawama让我意识到的那样,我没有勾选“已启用用户交互”框。已解决。

您缺少一些代码

您需要让点击调用该方法以
performsguewithidentifier
,而不仅仅是按住ctrl键并单击并拖动到下一个VC

到您的视图加载。确保已为imageView创建属性

然后创建
someMethod
方法:

func someMethod (sender: UITapGestureRecognizer? = nil)
{
    self.performSegueWithIdentifier("viewProfile", sender: self)
}
然后你就准备好了方法:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "viewProfile") {
            let vc = segue.destinationViewController as! ProfileController
            let x = sender as! UITapGestureRecognizer
            let location = x.locationInView(self.myBountiesTableView) as CGPoint
            let indexPath = self.myBountiesTableView.indexPathForRowAtPoint(location) as NSIndexPath?
            let cell = self.myBountiesTableView.cellForRowAtIndexPath(indexPath!) as! BountyCellNew
            vc.userId = cell.bounty.bountyCreatedById!.description
        }
    }

删除if条件并查看是否调用它。在方法中设置断点。请同时发布您的点击手势识别器代码。@CaptJak是的,我已经发布了that@CaptJak不,是的not@Abhinav没有代码。我在图像视图上放置了点击手势。这正是我在另一个VC中所做的,它工作得很好。我如何确保在没有点击手势识别器代码的情况下?我在我的其他VC中没有任何相同的设置。为什么我要在没有此代码的情况下这样做?包含此代码的好处是什么?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "viewProfile") {
            let vc = segue.destinationViewController as! ProfileController
            let x = sender as! UITapGestureRecognizer
            let location = x.locationInView(self.myBountiesTableView) as CGPoint
            let indexPath = self.myBountiesTableView.indexPathForRowAtPoint(location) as NSIndexPath?
            let cell = self.myBountiesTableView.cellForRowAtIndexPath(indexPath!) as! BountyCellNew
            vc.userId = cell.bounty.bountyCreatedById!.description
        }
    }