zoukankan      html  css  js  c++  java
  • 代码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 创建新页面了 实现跳转了。

       

       

       

       

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

       

    让明天,不后悔今天的所作所为
  • 相关阅读:
    [POJ1151]Atlantis
    [POJ1177]Picture
    [POJ1765]November Rain
    Adaptively handling remote atomic execution based upon contention prediction
    Webpack 2.0 的文档
    PAT乙级 1025. 反转链表 (25)
    PAT乙级 1024. 科学计数法 (20)(未通过全部测试,得分18)
    PAT乙级 1023. 组个最小数 (20)
    PAT乙级 1022. D进制的A+B (20)
    PAT乙级 1021. 个位数统计 (15)
  • 原文地址:https://www.cnblogs.com/-yun/p/4375588.html
Copyright © 2011-2022 走看看