早教吧作业答案频道 -->其他-->
点击不同cell怎样进入不同viewcontroller
题目详情
点击不同cell怎样进入不同viewcontroller
▼优质解答
答案和解析
实现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];
}
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];
}
看了 点击不同cell怎样进入不同...的网友还看了以下:
九6.上g的Cl溶解在vL水中,所得溶液的密度为ρg•mL-v,质量分数为w,物质的量浓度为cmo 2020-05-14 …
matlab 程序出错,帮我看看错在哪儿了函数function dvdt=huxi(t,v) gl 2020-05-16 …
电动势E=W/q单位不一致如何解释?电动势的单位为V功的单位为J电量的单位为C由欧姆定律得V=A* 2020-05-22 …
在密闭容器重进行可逆反应,A与B反应生成C,其反应速率分别用V(A).V(B).V(C)(mol/ 2020-05-23 …
能引起误差的一些操作(高中化学)1、用量筒量取液体(溶质)时,俯视读数,m(溶质)减小,V(溶液) 2020-06-07 …
标准状况下V L氨气溶解在1L水中(水的密度近似为1g/mL),所得溶液的密度为ρ g/mL,质量 2020-06-27 …
已知Fe3+与I-在水溶液中发生:2I-+2Fe3+=2Fe2++I2.该反应正反应速率和I-、F 2020-07-09 …
关于密度公式ρ=m/V,下列说法正确的是()A.ρ与m成正比,与V成反比B.同一种物质的密度一定相同 2020-10-30 …
当x→0时,无穷小量u=-x+sinx∧2与无穷小量v=x的关系是:A.u是比v高阶无穷小量V.u是 2020-12-09 …
为什么PH值相同,等体积的一元弱酸的c(酸)大于一元强酸的?用公式解释下PH相同,即c(H+)相同而 2020-12-31 …