2011-12-13 84 views
0

我在實現文件中使用了下面的代碼。問題是,當我點擊一行時,它不會將我帶到另一個視圖?其他視圖尚未加載iPhone應用程序

請幫助

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 

return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

return 3; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

} 

cell.textLabel.text = [NSString stringWithFormat:@"Vehicle List %d", [indexPath row]+1]; 

return cell; 
} 

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

if (self.vehic == nil) { 
    Vehicle *vehicle = [[Vehicle alloc] initWithNibName:@"Vehicle" bundle:[NSBundle mainBundle]]; 

    self.vehic = vehicle; 
} 

[self.navigationController pushViewController:self.vehic animated:YES]; 
} 
+0

如果你把一個NSLog裏面'didSelectRow ...'代碼執行?而Vehicle是UIViewController的子類? –

+0

給一些關於車輛和車輛物體的信息... – mAc

回答

1

對於要到另一個查看你應該正確處理這種方法: -

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

// on click on any row now it will go to Another View, let the other view be SecondViewController's View 

SecondViewController *viewController = [[SecondViewController alloc]initWithNibName:@"FirstViewController" bundle:nil]; 
[self presentModalViewController:viewController animated:YES]; 

} 

這就是全部。如果您遇到任何問題,請告訴我。 :)

+0

!感謝兄弟,你解決了我的問題。現在告訴我,如果每一行代表不同的數據,那麼如何做到這一點... – AppDeveloper

+0

請參閱dude cellForRowAtIndexPath方法自動調用表中的每一行,只要您在任何行上點擊TAP,就可以做一件事情。 didSelectRow方法中的APPDELEGATE類的數組,然後轉到Next ViewController。現在在cellForRowPathAtIndex像這樣設置: - [cell.textLable.text:YourArray ObjectAtIndex:indexPath.row] – mAc

+0

ok thanx :) ... – AppDeveloper

相關問題