2013-08-28 24 views
1

我有一個名爲「MainStoryboard_iPhone.storyboard」的故事板,它有2個視圖。第一個視圖有一個帶有公開按鈕的表格單元格。我可以將表格單元格拖放到其他視圖並顯示視圖,但是隻有當用戶在不使用segue的情況下單擊附件按鈕時,才需要以編程方式進行。 2個視圖的名稱是RootViewController和ProviderLookupViewController。目前我已經試過這段代碼,但不起作用,當我點擊單元上的附件按鈕時,它會報錯。註釋行是其他的東西,我想在附件按鈕中按動視圖板

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 
    UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" 
                bundle:nil]; 
    // ProviderLookupViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ProviderLookupViewController"]; 
    UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ProviderLookupViewController"]; 
    [self presentModalViewController:vc animated:YES]; 
    //[self.navigationController pushViewController:vc animated:YES]; 

} 
+0

你能添加錯誤信息嗎? – zbMax

+1

你說'2個視圖的名稱...'你的意思是UIViewController?順便說一下,使用'instantiateViewControllerWithIdentifier:'需要爲您的視圖控制器(實用程序/身份檢查器)設置標識符 – zbMax

+0

是的,第一個是RootViewController,標識符已設置。並得到錯誤,程序收到的信號:SIGABRT – Gamerlegend

回答

1

先給故事板ID StoryBoard id爲ProviderLookupViewController在您的方案並勾選使用故事板ID,然後在

ProviderLookupViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ProviderLookupViewController"]; 
[self presentModalViewController:vc animated:YES]; 

注:ProviderLookupViewController是你的標識符。

+0

的segue調用我找不到這個選項,在這個視圖是可用的,目前我點擊第二視圖與類:ProviderLookupViewController和身份它只有對象ID和標籤。我正在使用Xcode 4.2 – Gamerlegend

+0

是你使用故事板?抱歉用你的視圖名替換uiviewcontroller,例如:ProviderLookupViewController –

+0

然後,UIStoryboard * storyboard = self.storyboard; ProviderLookupViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@「ProviderLookupViewController」]; [self presentViewController:vc animated:YES completion:nil]; –

-1

從一個視圖控制器創建一個IB SEGUE到另一個。添加一些識別器對Segue公司,只使用

[self performSegueWithIdentifier:@"SomeSegueName" sender:someObject]; 
+0

Gamerlegend指定'不使用segue' – zbMax

+0

他沒有指出爲什麼。據我所知,他不知道他可以使用代碼 – nerowolfe

3

如果我是正確的:

1)從你的問題看來你有一個故事板,使用兩個視圖控制器,第一個是一個UITableViewController和UIViewController中的其他子類。

2)您想在用戶點擊披露按鈕時顯示第二個視圖。

鑑於您使用故事板而不是nib文件,我建議您使用segue,它可以解決您的問題,而無需編寫代碼。

一個表格視圖單元格可以有兩個segues,一個是如果你選擇了單元格,另一個是如果你選擇了accesory按鈕。從附件按鈕第二視圖控制器而不是做從小區的調速拖動與控制阻力,當菜單出現,你必須選擇下列Accesory行動,而不是下面的選項選擇Segue公司

enter image description here

的桌子視圖的原型單元必須具有公開附件啓用。從公用程序窗格(右側)執行此操作。配件不能沒有做到這一點。在圖片accessoy是詳細的披露。

enter image description here

公用事業窗格還讓你做SEGUE的。儘管使用附件操作,但圖片來自我的一個項目。

enter image description here

+0

當我控制從單元格拖動時我沒有得到Accessory Action選項。 ?我正在使用Xcode 4.2 – Gamerlegend

+0

您必須將單元格轉換爲單向類型,然後附件纔會出現在單元格上。一旦出現,請控制從附件拖動。 –

+0

@Gamerlegend我添加了一張圖片和更多解釋回答你的問題 –