【问题标题】:'NSInvalidArgumentException', reason: 'Receiver (**) has no segue with identifier '**'''NSInvalidArgumentException',原因:'Receiver (**) has no segue with identifier '**''
【发布时间】:2012-05-28 11:58:20
【问题描述】:

我真的希望以前没有人问过这个问题。我在这个网站上花了很多时间寻找解决方案,但一直没有想出一个解决方案。我正在尝试从名为 callPerformSegue 的函数中调用 performSegueWithIdentifier。当单击 UITableView 中某个部分的页脚中的 UIImageView 时,将调用 callPerformSegue。 callPerformSegue 函数如下:

- (void)callPerformSegue {
    [self performSegueWithIdentifier:@"bannerPressed" sender:self];
} 

我在 Storyboard 中正确识别了bannerPressed segue,因为如果我将 performSegueWithIdentifier 调用移到 didSelectRowAtIndexPath 中,则 segue 会正确执行。但是,当从 callPerformSegue 调用时,我得到以下信息:

'NSInvalidArgumentException',原因:'Receiver (****) has no segue with identifier 'bannerPressed''

有什么想法吗?

更新:

我从我的 BannerView 类调用函数 callPerformSegue,它是 UIImageView 的子类。当有人点击横幅时,此类处理触摸事件,并确定收到触摸时显示的图像。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //Get the time of the click
    NSDate *animationStart;
    NSDate *clickTime;
    clickTime = [NSDate date];

    NSMutableArray *bannerArrayFromDictionary = [self.bannerDictionary objectForKey:[NSNumber numberWithInt:self.currentSection]];

    //Calculate the time elapsed since animationStart and clickTime
    animationStart = [bannerArrayFromDictionary objectAtIndex:0];

    int secondsElapsed = [clickTime timeIntervalSinceDate:animationStart];

    //Determine the number of elements for the section
    int numberOfImagesForSection = [bannerArrayFromDictionary count] - 1;

    //Determine the index into the animationArrary
    int imageClickedIndex = (secondsElapsed / 5) % numberOfImagesForSection;

    //Add 1 to the index to compensate for the timestamp
    imageClickedIndex++;

    //Get the image name
    NSString *clickedImage = [bannerArrayFromDictionary objectAtIndex:imageClickedIndex];

    //Set the image name in CategoryViewController so that a segue to the Detail Page can be performed
    CategoryViewController *view = [[CategoryViewController alloc] init];
    view.currentImage = clickedImage;
    [view callPerformSegue];

}

【问题讨论】:

  • 你是怎么调用方法callPerformSegue的?
  • 感谢@luyuan的回复,我更新了原帖。

标签: ios segue


【解决方案1】:

横幅视图.h

@property (strong,nonatomic) IBOutlet id  delegate;

横幅视图.m

[self.delegate callPerformSegue];

CategoryViewController.m

bannerView.delegate = self;

【讨论】:

  • 我很抱歉@luyuan,但我现在感觉很紧张。我现在在业余时间才学习 iOS 几个月,所以我有很多东西要学。我有几个来自 CategoryViewController VC 的 segues,它们都可以正常工作。只有在某个部分中显示横幅时,bannerView UIImageView 才会在 CategoryViewController 的 viewForFooterInSection 中以编程方式创建。如果单击该 UIImageVIew,将执行 touchesBegan 函数,然后调用 callPerformSegue。
  • 再次感谢@卢元。我在 BannerView.h 中添加了插座(我必须在 BannerView.h 中转发声明 CategoryViewController 类。我尝试在 BannerView.h 中导入 CategoryViewController.h 但我猜有一个循环引用问题,因为我有 #import BannerView.h在 CategoryViewController.h 中找不到 BannerView),并在 BannerView.m 中添加了代码。但是,我无法将 CategoryViewController 视图链接到 BannerView.h 中的插座。似乎我只能链接到 CategoryViewController.h 中的插座。我还缺少其他东西吗?
  • @user1292943 然后,尝试将 BannerView 的委托设置为 CategoryViewController.h,并调用 [self.delegate callPerformSegue]。我会为你更新答案,请稍等。
  • 再次感谢@luyuan,我根据你的回答更新了我的代码,但是没有调用CategoryViewController中的callPerformSegue函数。该插座是否需要以某种方式接线? “尝试将 BannerView 的委托设置为 CategoryViewController.h”是什么意思?我需要在 CategoryViewController.h 中添加什么吗?我在 CategoryViewController.h 的界面部分确实有以下内容: BannerView *view;
  • @user1292943 现在不需要连线了。你能告诉我更多相关的代码吗?比如你如何添加bannerview?
【解决方案2】:

您可能将 Segue 连接到 TableView 单元格,而不是连接到 ViewController。我养成了始终将 Segues 连接到 VC 而不是 Buttons 或 TableView Cells 的习惯。要修复,删除您现在拥有的 Segue 并将其重新连接到 VC 而不是 TableView Cell。确保命名相同。

【讨论】:

  • 感谢@ElJay,这实际上是我尝试过的第一件事(刚刚又做了一次),但问题仍然存在。我的项目中有很多不同的视图控制器和 segues,之前也曾为此苦苦挣扎过。
猜你喜欢
  • 1970-01-01
  • 2014-11-14
  • 2016-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 1970-01-01
相关资源
最近更新 更多