iphone - Xcode 中的 Segue 头痛

标签 iphone objective-c ios xcode ios4

我有一个 tableview,我创建了一个 segue 将它推送到另一个 View Controller 。时不时地,这个 segue 会在我不碰它的情况下中断,我可以保证。我什至没有编辑我放入的文件。

我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *acell = [tableView cellForRowAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"cellWasSelected" sender:acell];
}



- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"cellWasSelected"])
    {
        if ([sender isKindOfClass:[UITableViewCell class]])
        {
            UITableViewCell *selectedCell = sender;
            ViewController *myDetViewCont = segue.destinationViewController;
            myDetViewCont.navigationItem.title = selectedCell.textLabel.text;
        }
    }
}

首先,在单击一个单元格后,xcode 会将我定向到此 segue 推送到的文件。 它将我重定向到这里:action:@selector(handleSingleTap:)]; 我用它来触发我的图像:[self.navigationController popToRootViewControllerAnimated:YES]

如果我在线程 1 中选择我的主视图,我看到的问题是:

[self performSegueWithIdentifier:@"cellWasSelected"sender:acell];

但是我用了这个一千次,但我没有改变它就开始崩溃了。

最佳答案

您的代码没有任何错误,问题出在其他地方。可能是您没有在界面生成器中为 segue 提供标识符。试试这段代码。它在我这边工作,如果你的文件没有任何问题,它也应该在你这边运行。

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

NSString* identifier = [segue identifier];

if ([identifier isEqualToString:@"cellWasSelected"]) {
    NSLog(@"Performing Seque");

    if ([sender isKindOfClass:[UITableViewCell class]]) {
        NSLog(@"correct");
        UITableViewCell *selectedCell = sender;
        UIViewController* myDetViewCont = segue.destinationViewController;
        myDetViewCont.navigationItem.title = selectedCell.textLabel.text;
    }
}

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSLog(@"%@",@"Cell Selected");
   UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
   [self performSegueWithIdentifier:@"cellWasSelected" sender:cell];
}

附言如果您仍然遇到问题,那么您可能是 Storyboard的新手,您需要足够的知识来解决这些问题。 http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

关于iphone - Xcode 中的 Segue 头痛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11997273/

相关文章:

ios - %i 和 %li 有什么区别?

objective-c - 在 iOS 中设计购物车时,我应该使用核心数据还是全局 Cart 类?

iOS 应用内购买在开发中有效,但在生产中无效

ios - Flutter(iOS) -"No CupertinoLocalizations found",如何解决?

iphone - UIView 与 UIViewController

iphone - UIAlertViewDelegate 扩展协议(protocol)

ios - 如何在 iOS 上捕获的视频中添加水印 - Swift 编程

ios - tableview按钮点击需要在ios中使用pickerview

iphone - NSString 包含 : <null> and is crashing my app

ios - 在 NSString 中动态查找单词