表題の通りのことを実装しようとしています。
tableView(mainTableView)上のセル内にUIButtonが配置されていて、そのボタンのタップ時のイベントとして現在表示されているtableViewの上にさらに、別のtableView(subTableView)が乗ったUIViewを表示させることをしたいです。
1つのviewController内で複数のtableViewを扱う際にはtagをつけて区別する方法があるということだったので試してみたのですが、実装してみるとsubTableViewの方ではデータが反映されておらず、空のセルしか表示されません。
lang
1- (void)viewDidLoad { 2 [super viewDidLoad]; 3 //subTableView生成 4 subTableView = [[UITableView alloc] initWithFrame:CGRectMake(50, 50, 200, 400)]; 5 6 mainTableView.dataSource = self; 7 mainTableView.delegate = self; 8 subTableView.dataSource = self; 9 subTableView.delegate = self; 10 11 //tag付け 12 mainTableView.tag = 0; 13 subTableView.tag = 1; 14} 15 16- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 17 if (tableView.tag == 0) { 18 return 5; 19 } else { 20 return 3; 21 } 22} 23 24- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 25 if (tableView.tag == 0) { 26 cell.textLabel.text = @"main"; 27 [cell.button addTarget:self action:@selector(showTable:) forControlEvents:UIControlEventTouchUpInside]; 28 29 return cell; 30 } else { 31 cell.textLabel.text = @"sub"; 32 33 return cell; 34 } 35} 36 37//buttonのアクション 38- (void)showTable:(UIButton *)sender{ 39 //表示するViewを生成 40 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)]; 41 42 [view addSubview:subTableView]; 43 [self.view addSubview:view]; 44}
mainTableViewの方は問題なく表示されているのですが何が原因なのでしょうか。
お力貸していただけるとありがたいです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。