生活随笔
收集整理的这篇文章主要介绍了
代码UITableView点击cell跳转
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
首先,在tableViewController中设置好 代理和数据源方法:
1 @interface FirstTableViewController ()<UITableViewDataSource,UITableViewDelegate>
实现一系列的数据源方法:让其显示数据 例如 简单显示 几行 : 1 #pragma mark 数据源方法
2
3 /**
4
5 * 一共有多少组数据
6
7 */
8
9 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
10
11 {
12
13 return 2 ;
14
15 }
16
17 /**
18
19 * 第section组有多少行
20
21 */
22
23 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
24
25 {
26
27 if (section == 0) {
28
29 return 2 ;
30
31 }else{
32
33 return 4 ;
34
35 }
36
37 }
38
39 -(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
40
41 {
42
43 UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
44
45 cell.textLabel.text = @"11";
46
47 return cell ;
48
49 }
添加此方法实现跳转。 1 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
2
3 {
4
5 SecondTableViewController *SVC = [[SecondTableViewController alloc]init];
6
7 [self.navigationController pushViewController:SVC animated:YES];
8
9 }
注:点击cell 后先创建个UIview 之后再用navigationController 推送出来
这样就可以成功通过点击cell 创建新页面了 实现跳转了。
---------摘自百度经验,有删改,感谢原著
转载于:https://www.cnblogs.com/-yun/p/4375588.html
总结
以上是生活随笔为你收集整理的代码UITableView点击cell跳转的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。