2011-03-21 185 views
0

我正在製作一個基於導航的應用程序,並且我發現我的應用程序存在缺陷。即使我有多個按鈕,每個按鈕都有自己的標題,無論按下哪個按鈕,按鈕都會將您引導到同一個屏幕。有沒有一種方法可以確保每個按鈕導致一個特定於該按鈕的頁面被按下。比如點擊選項,它會將您帶到選項菜單中,而不是點擊圖像,並將它帶到選項菜單。任何幫助,將不勝感激謝謝。 這是我的堆棧彈出方法:指定導航按鈕

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    Anotherviewcontroller *detailViewController = [[Anotherviewcontroller alloc] initWithNibName:@"Anotherviewcontroller" bundle:nil]; 

    detailViewController.currentItem = @"Years"; 

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

    [detailViewController release]; 

} 
+0

請發佈在「 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {」部分的ViewController代碼中的代碼。 – 2011-03-21 09:24:20

回答

0

您應該使用indexPath以確定哪個按鈕/電池已被選中,然後,也許在與switch語句,如果有很多,建立相應的控制器。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     if(indexPath.row == 0) { 
     Anotherviewcontroller *detailViewController = [[Anotherviewcontroller alloc] initWithNibName:@"Anotherviewcontroller" bundle:nil]; 
     detailViewController.currentItem = @"Years"; 
     [self.navigationController pushViewController:detailViewController animated:YES]; 
     [detailViewController release]; 

     } else { 
     MessageViewController *messageViewController = [[MessageViewController alloc] initWithNibName:@"Messageviewcontroller" bundle:nil]; 
     [self.navigationController pushViewController:messageViewController animated:YES]; 
     [messageViewController release]; 
     } 
} 
+0

這真的很有幫助,但我有一個花名冊類型設置。在哪裏我有名字>年> PDFNameList> PDF文檔....我想要每個名稱導致其特定的一套yea和PDF標題....這是否意味着我必須爲每個名稱創建視圖控制器? – Seergeek 2011-03-25 07:21:33

+0

不,你必須改變你的控制器來處理你的輸入:year和pdf等等。然後,您只需確定當前indexPath選擇哪一年/ pdf。編寫一個方法如下:' - (MyData *)dataForIndexPath(NSIndexPath *)anIndexPath ...'你在didSelectRowAtIndexPath中調用並將你的數據傳遞給你的控制器。 – 2011-03-25 08:47:47

0

您可以設置indexPath.row每個BTN的標籤,當你創建細胞,然後在didSelectRowAtIndexPath方法可以檢查該標記。

+0

我該怎麼辦? – Seergeek 2011-03-25 07:22:46

+0

如果我是對的,那麼你在單元格中有這些按鈕。你可以將setTag函數調用到這些btns中,併爲所有btn調用一個通用目標,並在該目標函數中檢查按鈕標記。 – saadnib 2011-03-25 08:49:51