问题描述
- 关于table跳转的疑虑,手写了为什么跳转不了(只写了前两个单元格),我是小白请原谅
-
#import "RootTableViewController.h"
#import "TableViewController_1.h"
#import "TableViewController_2.h"
@interface RootTableViewController ()@end
@implementation RootTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"设置";
_muArr = @[@[@"飞行模式",@"无线局域网",@"蓝牙",@"蜂窝移动网络",@"个人热点",@"运营商"],@[@"通知",@"控制中心",@"勿扰模式"]];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [_muArr count];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ((NSArray *)_muArr[section]).count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rootCellIdentifier" forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"rootCellIdentifier"];
}
cell.textLabel.text = [((NSArray *)_muArr[indexPath.section]) objectAtIndex:(indexPath.row)];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
TableViewController_1 *table_1 = [[TableViewController_1 alloc]init];
TableViewController_2 *table_2 = [[TableViewController_2 alloc]init];
UIViewController *uiviewcontroller = [[UIViewController alloc]init];
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
uiviewcontroller = table_1;
break;
case 1:
uiviewcontroller = table_2;
break;
default:
break;
}
}[self.navigationController pushViewController:uiviewcontroller animated:YES];
}
@end
/****************/
#import "TableViewController_1.h"@interface TableViewController_1 ()
@end
@implementation TableViewController_1
- (void)viewDidLoad {
[super viewDidLoad];
_arr_1 = @[@[@"你该吃药了",@"你病的不轻"],@[@"我是医生",@"我是你的医生",@"我是你一辈子的医生"]];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _arr_1.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ((NSArray *)_arr_1[section]).count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier" forIndexPath:indexPath];// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIdentifier"];
}
cell.textLabel.text = ((NSArray *)_arr_1[indexPath.section])[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)viewDidLoad {
解决方案
tableview没有设置数据源和代理。