首页 > 其他 > 详细

代码实现UITableView点击cell跳转

时间:2015-03-29 14:58:49      阅读:176      评论:0      收藏:0      [点我收藏+]
  1. 首先,在tableViewController中设置好 代理和数据源方法:

    @interface FirstTableViewController ()<UITableViewDataSource,UITableViewDelegate>

  2.  实现一系列的数据源方法:让其显示数据 例如 简单显示 几行 :

    #pragma mark 数据源方法 

    /**

     *  一共有多少组数据

     */

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        return 2 ;

    }

    /**

     *  第section组有多少行

     */

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        if (section == 0) {

            return 2 ;

        }else{

            return 4 ;

        }

    }

     -(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];  

        cell.textLabel.text = @"11";

          return cell ;

    }

  3.  添加此方法实现跳转。

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        SecondTableViewController *SVC = [[SecondTableViewController alloc]init];

        [self.navigationController pushViewController:SVC animated:YES];

    }

    注:点击cell 后先创建个UIview 之后再用navigationController 推送出来

    这样就可以成功通过点击cell 创建新页面了 实现跳转了。

     

     

     

     

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

代码实现UITableView点击cell跳转

原文:http://www.cnblogs.com/-yun/p/4375588.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!