0

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

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

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

'NSInvalidArgumentException',原因:'接收者(****)没有标识符'bannerPressed'的segue'

有任何想法吗?

更新:

我从我的 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];

}
4

2 回答 2

2

横幅视图.h

@property (strong,nonatomic) IBOutlet id  delegate;

横幅视图.m

[self.delegate callPerformSegue];

类别视图控制器.m

bannerView.delegate = self;
于 2012-05-28T12:43:45.770 回答
1

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

于 2012-05-28T12:21:50.200 回答