您好
我的视图是导航控制器内的表格视图。我使用别人的代码来做这件事,我知道这是编写代码时的人的意图,但是当我触摸表格单元格时,它会将我带到同一个视图。您如何批评下面的代码,为每个不同的表格单元加载不同的笔尖。
MoreTableViewController.h
@interface MoreTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *moreTableView;
NSMutableArray *moreArray;
AboutDetailViewController *aboutDetailViewController;
}
@property (nonatomic, retain) NSMutableArray *moreArray;
@property (nonatomic, retain) AboutDetailViewController *aboutDetailViewController;
@end
MoreTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (self.aboutDetailViewController == nil) {
AboutDetailViewController *aboutD = [[AboutDetailViewController alloc] initWithNibName:@"AboutDetailViewController" bundle:nil];
self.aboutDetailViewController = aboutD;
[aboutD release];
}
aboutDetailViewController.title = [NSString stringWithFormat:@"%@", [moreArray objectAtIndex:row]];
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.moreNavController pushViewController:aboutDetailViewController animated:YES];
}
我必须做一个if声明吗?如果是这样,我将如何编写代码。我需要我能得到的所有帮助。 谢谢你的帮助。
答案 0 :(得分:1)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
switch(row) {
case 0:
// First row
// Push xib
break;
case 1:
// Second row
// Push xib
break;
}
}
答案 1 :(得分:0)
if(indexPath.row == 0)
{
AboutDetailViewController *aboutD = [[AboutDetailViewController alloc] initWithNibName:@"AboutDetailViewController" bundle:nil];
self.aboutDetailViewController = aboutD;
[aboutD release];
}
else if(indexPath.row == 1)
{
}
else if(indexPath.row == 2)
{
}
确定....
你必须在下面的方法中写下所有这些东西
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {