代码UITableView点击cell跳转

  1. 首先,在tableViewController中设置好 代理和数据源方法:

     

     1 @interface FirstTableViewController ()<UITableViewDataSource,UITableViewDelegate> 

  2.  实现一系列的数据源方法:让其显示数据 例如 简单显示 几行 :
     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 }

     

  3.  添加此方法实现跳转。
    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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值