开发者社区> 问答> 正文

tablevView 的跳转问题

//

// ViewController.m

// ios-TabelView

//

// Created by ma c on 15/8/28.

// Copyright (c) 2015年 sxt. All rights reserved.

//

import "ViewController.h"

import "Second.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tabelView;

@end
@implementation ViewController

  • (void)viewDidLoad {

    [super viewDidLoad]; 
    

// self.view.backgroundColor = [UIColor whiteColor];

//设置数据源的两种方法 

//1·代码设置

//2·拖线

self.tabelView.dataSource = self; 

self.view.backgroundColor = [UIColor whiteColor]; 

}

  • (BOOL)prefersStatusBarHidden
    {

return YES;
}

/**
有两组

*/

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{
return 2;

}

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

{

//    NSLog(@"numberOfRowsInSection-%d", section); 

  /**从上面可知,有两组,所有由这里判断,第0组有三行,第二组有四行*/ 

if (section == 0) { 

    return 2; 

} else { 

    return 2; 

} 

}

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

{

/**每组里面的每一行显示的内容*/ 

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

if(indexPath.section == 0) //第一组--两行 

{ 

  if(indexPath.row==0) 

  cell.textLabel.text = @"奥迪"; 

  else if(indexPath.row==1) 

    cell.textLabel.text =@"奔驰"; 

}else if(indexPath.section == 1) 

{ 

    if (indexPath.row == 0) { 

        cell.textLabel.text = @"法拉利"; 

    }else if (indexPath.row == 1) 

      cell.textLabel.text = @"兰博基尼"; 

  } 

   return cell; 

}

/*显示section组的头部标题/

  • (NSString )tableView:(UITableView )tableView titleForHeaderInSection:(NSInteger)section

{

   if(section == 0) 

       return @"德系轿车"; 

    else 

      return @"英系轿车"; 

}
/*显示section的尾部标题/

  • (NSString )tableView:(UITableView )tableView titleForFooterInSection:(NSInteger)section

{

if (section == 0) { 

    return @"宇宙第一品牌"; 

}else 

   return @"牛哄哄"; 

}

  • (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath

{

NSLog(@"哈哈"); 

Second *se = [[Second alloc]init]; 

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

}

@end

我的需求是实现点击行 跳转到second上面去 ,second是继承UIViewController的,但是跳不过去是怎么回事,代理已经构建完成,拖的线???? 我还是ios菜鸟求解释!!!!! 急急急!!!!!

展开
收起
杨冬芳 2016-06-27 16:28:21 1768 0
1 条回答
写回答
取消 提交回答
  • IT从业

    你外面有uinavigationcontroller吗?
    self.tableView.delegate = self;+上

    2019-07-17 19:47:47
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载