2012-10-03 96 views
0

Folks, 我需要关于Storyboard的帮助。 我有一个带有表格和视图的Storyboard,我想单击一个单元格并为视图执行交易。 我将DetalheMeuPostoAmigo设置为View并在didSelectRowAtIndexPath中将其作为代码进行调用。Storyboard with Xcode 4.5

当我运行应用程序时,我没有收到任何错误,但事务不起作用。我使用警报测试并确定。我查阅了很多很多次的代码...

Top10.m 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    DetalheMeuPostoAmigo *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"]; 
    [self.navigationController pushViewController:detalhesMeuPostoAmigoVC animated:YES]; 
} 

Link to Storyboard Image

+0

试试这个:UIStoryboard *分镜= self.storyboard;而不是thisUIStoryboard * storyboard = [UIStoryboard storyboardWithName:@“MainStoryboard”bundle:nil]; –

+0

Tks Rahul,我尝试过,但没有工作,你有另一种理想吗? – Cauca

回答

2

我不是这方面的专家,但尽量利用现有的VC:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];  
    YOURCURRENTVC *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"]; 
    [self.navigationController pushViewController:detalhesMeuPostoAmigoVC animated:YES]; 
} 
+0

或尝试UIViewController而不是YOURCURRENTVC ... – Romo

+0

Tks Romo,我试过但没有工作,你有另一种理想吗? – Cauca

+1

这就是我在我的项目中做到的: – Romo

1

我不知道回答。但过去我也有类似的问题。检查self.navigationController == null如果它为null,那么这里是你的问题。

宝儿sorte

+0

TKS塞尔吉奥,我试过但没有工作,你有另一种理想吗? – Cauca

+0

如果你在另一个ViewController中有一个ViewController,你可能需要调用ViewController,它是你的'mainViewController'。 尝试从另一个视图控制器进行推送。 我刚看到你的测试。尝试从其他视图控制器调用。有时我有多个viewcontroller不是都有一个navigationcontroller。 –

1

你为什么不只是有Segue公司在表格单元格中创建?选择表格单元格,按下控制键并将箭头拖到您的视图控制器并选择按下。给Segue标识符,你就完成了!

你的代码的问题是你没有在UINavigationController中嵌入的UITableview。通过选择“编辑器 - >嵌入 - >导航控制器”进行嵌入。那么你的代码应该工作。

仅供参考故事板上的articles真棒!

+0

Tks applefreak,我尝试过,但没有工作,你有另一种理想吗? – Cauca

+0

Tk为物品... – Cauca

+0

你试过了什么?你的问题没有任何复杂性。它应该直接工作。阅读这些文章,你会掌握故事板。 – applefreak

0

感谢所有的答案,我测试了所有选项,但没有成功后,Sergio的测试下方

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 

     DetalheMeuPostoAmigo *detalhesMeuPostoAmigoVC = [storyboard instantiateViewControllerWithIdentifier:@"DetalheMeuPostoAmigo"]; 


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

    if (detalhesMeuPostoAmigoVC == nil) { 
     NSLog(@"Is null?"); // Here is not Null 

    } 
    if (self.navigationController == nil) { 
     NSLog(@"Is null?"); // Here is Null 

    } 
1

您最初的ViewController不在NavigationController。

在你的故事板中选择TableViewController并从菜单中选择

编辑器 - >嵌入在 - >导航控制器

enter image description here