2011-02-24 22 views

回答

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

      switch (indexPath.row) { 
    case "X" 
     // Allocate the viewController 
     [navigationcontroller.pushViewController:"yourviewcontroller" animated:YES]; 
     [release "yourviewcontroller"]; 
     break; 

    default: 
     break; 
} 
} 

編輯:沒有意識到你想什麼。正如shani所說,如果沒有必要,你不應該爲每一行創建一個viewcontroller。嘗試更改每行的數據源,但使用相同的viewcontroller。所以忘記這個實現。

3

首先,您不需要爲每一行設置不同的視圖控制器(除非您有足夠的理由這樣做)。

正確的方法是設置1個視圖控制器,該視圖控制器將適合原始數據中的所有單元格,並根據所選行更改其數據。

你做到這一點的方法是:

in the - DidSelectRowAtIndexPath function in your implementation file you shuld: 

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

//allocate your view controller 
     DetailedViewController *detailedViewController = [[DetailedViewController alloc] init]; 

//send properties to your view controller 
     detailedViewController.property1 = someProperty1; 
     detailedViewController.property2 = someProperty2; 

//push it to the navigationController 
     [[self navigationController] pushViewController:detailedViewController animated:YES]; 
     [detailedViewController release]; 
    } 

我不建議您將使用蘋果的例子開始,他們是偉大的,有很多人:

http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318

祝你好運

0

簡單:

創建一個第二把你的視圖控制器在此委託功能:

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

} 
2

@kashyap在didSelectRowAtIndexPath委託UITableView你要檢查其上indexPath你點擊的條件,並打開viewControllers您已經相應地做出

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


    FirstViewController *firstViewController = [[FirstViewController alloc]  initWithNibName:@"FirstViewController" bundle:nil]; 
    SecondViewController *secondViewController = [[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil]; 

    switch (indexPath.row) { 
     case 0: 
      [self.navigationController pushViewController:firstViewController animated:YES]; 
      [firstViewController release]; 
      break; 
     case 1: 
      [self.navigationController pushViewController:secondViewController animated:YES]; 
      [secondViewController release]; 
      break; 
    }//Likewise do for the no of rows you have in your `UITableView` 

希望你明白我的意思.....祝你好運!

0

這聽起來像使用UINavigationController是你想要的。

然後您從表視圖把你的「第一個視圖」導航控制器的堆棧,例如,從您的UITableView委託:

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

    // indexPath.row == 0 
    FirstViewController* firstVC = [[FirstViewController alloc] initWithNibName...]; 
    [self.navigationController firstVC animated:YES]; 
    [firstVC release]; 

    ... 
} 
0

這是一個,我得到了問題,當我第一次的事情開始。這是我爲此使用的代碼。 在subviewcontroller我有我自己的構造像

-(id)initWithName:(NSString*)naMe 
{ 
    name=naMe; 
    return self; 
} 

而且在didSelectRowAtIndexPath委託方法UITableView。我ALLOC它

MyListView mylistview=[[MyListView alloc] initWithName:@"name"]; 

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

[mylistview release]; 
0
NSInteger row = indexPath.row; 



UIViewController *newFrontController = nil; 

if (row == 0) 
    { 
     YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; 
     newFrontController = [[UINavigationController alloc] initWithRootViewController:peopleViewController]; 
     [self.navigationController setNavigationBarHidden:YES]; 
    } else if(row == 1){ 
//do your code 
} 

中的tableView爲此在didSelectRowAtIndexPath方法。

相關問題