2012-10-03 95 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