生活随笔
收集整理的這篇文章主要介紹了
代码UITableView点击cell跳转
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
首先,在tableViewController中設(shè)置好 代理和數(shù)據(jù)源方法:
?
?1 @interface FirstTableViewController ()<UITableViewDataSource,UITableViewDelegate>?
?實(shí)現(xiàn)一系列的數(shù)據(jù)源方法:讓其顯示數(shù)據(jù) 例如 簡(jiǎn)單顯示 幾行 : 1 #pragma mark 數(shù)據(jù)源方法
2
3 /**
4
5 * 一共有多少組數(shù)據(jù)
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 } ?
?添加此方法實(shí)現(xiàn)跳轉(zhuǎn)。 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 } ?
注:點(diǎn)擊cell 后先創(chuàng)建個(gè)UIview 之后再用navigationController 推送出來(lái)
這樣就可以成功通過(guò)點(diǎn)擊cell 創(chuàng)建新頁(yè)面了 實(shí)現(xiàn)跳轉(zhuǎn)了。
?
?
?
?
---------摘自百度經(jīng)驗(yàn),有刪改,感謝原著
?
轉(zhuǎn)載于:https://www.cnblogs.com/-yun/p/4375588.html
總結(jié)
以上是生活随笔為你收集整理的代码UITableView点击cell跳转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。