实现UITableView中点击不同cell进入不同Controller的方法

1>定义一个NSMutableArray的变量,如NSMutableArray *menuList;
2>将要加入cell的对象以字典的方式加入menuList中。
self.menuList = [NSMutableArray array];
//for showing various UIButtons:
ButtonsViewController *buttonsViewController = [[ButtonsViewController alloc] init];
[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"ButtonsTitle",@""), kTitleKey,
NSLocalizedString(@"ButtonsExplain",@""), kExplainKey,
buttonsViewController, kViewControllerKey,
nil]];
[buttonsViewController release];

//for showing various UIControls:
ControlsViewController *controlsViewController = [[ControlsViewController alloc] init];
[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"ControlsTitle",@""), kTitleKey,
NSLocalizedString(@"ControlsExplain",@""), kExplainKey,
controlsViewController, kViewControllerKey,
nil]];

//for showing various UITextFields:
TextViewController *textFieldViewController = [[TextViewController alloc] init];
[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"TextFieldTitle",@""), kTitleKey,
NSLocalizedString(@"TextFieldExplain",@""), kExplainKey,
textFieldViewController,kViewControllerKey,
nil]];
[textFieldViewController release];
3。通过objectforKey取值。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *targetViewController = [[self.menuList objectAtIndex: indexPath.row] objectForKey:kViewControllerKey];
[[self navigationController] pushViewController:targetViewController animated:YES];
}

你可能感兴趣的:(实现UITableView中点击不同cell进入不同Controller的方法)