• 代码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 创建新页面了 实现跳转了。

       

       

       

       

      ---------摘自百度经验,有删改,感谢原著

       

    让明天,不后悔今天的所作所为
  • 相关阅读:
    spark 1.1.0 单机与yarn部署
    hadoop 2.5.1单机安装部署伪集群
    perl C/C++ 扩展(五)
    perl C/C++ 扩展(一)
    perl C/C++ 扩展(二)
    perl C/C++ 扩展(三)
    perl C/C++ 扩展(四)
    SpiderMonkey 入门学习(一)
    新装centos 6.5 基本配置
    Linux(16):Shell编程(3)
  • 原文地址:https://www.cnblogs.com/-yun/p/4375588.html
Copyright © 2020-2023  润新知