2

问题:在选择一个特定的 时,应该打开uitableviewcell一个新的。DetailViewController我已经编写了代码,didSelectRowAtIndexPath但是当我单击单元格时,它向我显示运行时错误。

我试过打电话,[self.navigationController presentModalViewController:jacket animated:YES ];但是当我这样做时,我的视图控制器没有打开。

我尝试的另一种方法是通过 [self.navigationController performSegueWithIdentifier:@"JacketDetails" sender:self ];.

我在检查器中有“JacketDetails”的segued 中的指定标识符,但在这里我得到一个运行yime 错误。我已经从UITABLEVIEWCELLto上钩了 Segue VIEWCONTROLLER

当我单击该行时JacketDetailViewController应该打开。我已经创建了类JacketDetailViewController,并且New ViewController我已经在检查器中为此设置了类。

我不知道为什么它没有显示 segue ,我已经在检查器中给出了标识符并正确地连接tableviewcell到新的视图控制器。

JacketDetailViewController我想显示夹克列表。目前它是空白的ViewController

我的代码如下。你能提出一个解决方案吗?我是这个领域的自学初学者。我可能犯了一些小错误。我已经用谷歌搜索了我的问题并试图解决它,但我已经在这里停留了几天。

TshirtDetailViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.

    [tableView deselectRowAtIndexPath:indexPath animated:YES ];

    JacketDetailController *jacket =[[JacketDetailController alloc]init];

    NSInteger index =indexPath.row;

    NSLog(@"Row:%d",index);


    NSString *titleString = [[NSString alloc] initWithFormat:[jackets objectAtIndex:indexPath.row]];


    NSLog(@"%@",titleString);
    jacket.title=titleString;


    // ...
    // Pass the selected object to the new view controller.

    [self.navigationController performSegueWithIdentifier:@"JacketDetails" sender:self ];


  //  [self.navigationController presentModalViewController:jacket animated:YES ];

}


@end

控制台中的错误:

2013-01-07 10:52:21.020 KidsShopee[617:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x6a5fac0>) has no segue with identifier 'JacketDetails''

*** First throw call stack:

(0x13bf052 0x1550d0a 0xdd24b 0x3e8e 0xa671d 0xa6952 0x92e86d 0x1393966 0x1393407 0x12f67c0 0x12f5db4 0x12f5ccb 0x12a8879 0x12a893e 0x16a9b 0x1b08 0x1a65 0x1)
terminate called throwing an exception(gdb) 
4

5 回答 5

3

尝试使用这些行打开视图:

    YoutubeViewController *objYoutubeViewController = [[YoutubeViewController alloc]initWithNibName:@"YoutubeViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:objYoutubeViewController animated:YES];
    [objYoutubeViewController release];

代替 YoutubeViewController 给出您的视图控制器类名称并更改这些行

根据你和检查。如果你使用情节提要,请尝试如下:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 bookmarkViewController *myVC = (bookmarkViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"bookmarkViewController"]
[self presentModalViewController:myVC animated:YES];

代替 bookmarkViewController 给出您的控制器名称并检查。在拖放视图中

controller in main storyboard give right class name like below images: enter image description here

in place of my bookmarkViewController name give your view controller name that you want to open.

于 2013-01-07T05:30:32.710 回答
1

Don't call performSegueWithIdentifier:sender: on the navigation controller! Only your custom viewController can have segues. Call it on self.

Replace

[self.navigationController performSegueWithIdentifier:@"JacketDetails" sender:self ];

with

[self performSegueWithIdentifier:@"JacketDetails" sender:[tableView cellForRowAtIndexPath:indexPath]];
于 2013-01-07T06:16:38.090 回答
0

Can try with this-

JacketDetailController *jacket =[[JacketDetailController alloc]initWithNibName:@"JacketDetailController" bundle:nil];];///Change string as your nib name.

Then if its navigation base application-

[self.navigationController pushViewController:jacket animated:YES];

Then is its viewController base application-

[self presentModalViewController:jacket animated:YES];
于 2013-01-07T05:31:50.347 回答
0

Based on the error you are getting "has no segue with identifier 'JacketDetails'", something is not right with your call to the segue. I have found that I have problems with seque names working properly unless I copy and paste from the name I gave the seque in the storyboard into my .m file. Even if the spelling and case is correct, I have found many times, copying and pasting has fixed the problem.

于 2013-01-07T05:42:01.030 回答
0

If you hooked up a segue in the storyboard from the table view cell to another controller, then you don't need any of this code at all to make the segue fire. You should be implementing prepareForSegue to pass the information you need to the detail controller, but no other code is necessary.

于 2013-01-07T05:42:15.057 回答