2011-12-13 68 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

相关问题