【发布时间】:2014-11-12 00:59:55
【问题描述】:
我想将自定义 UITabBar 实现添加到 UITableViewCell。
如果 UITableViewCell 本身就是 UIViewController 我可以使用视图控制器包含,但它不是。
我现在能做的最好的就是将TabBar's 视图添加到cellForRowAtIndexPath 中单元格的contentView:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
NSString *cellID;
UITableViewCell *cell;
cellID = @"TabCell";
cell = [tableView dequeueReusableCellWithIdentifier:cellID] ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell.contentView.backgroundColor = UIColor.blueColor;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIViewController *vc1 = [UIViewController new];
vc1.view.backgroundColor = UIColor.magentaColor;
vc1.title = @"TAB1";
UIViewController *vc2 = [UIViewController new];
vc2.view.backgroundColor = UIColor.purpleColor;
vc2.title = @"TAB2";
tabBarController.delegate = self;
tabBarController.viewControllers = @[vc1, vc2];
[cell.contentView addSubview:tabBarController.view];
return cell
}
问题是单元格只显示TabBar 的视图,而不是TabBar 控件本身。
如何在UITableViewCell 中显示整个TabBar?
【问题讨论】:
-
你能截图看看现在单元格的样子吗
-
将视图控制器放在表格视图单元格中的想法让我感到紧张。你能告诉我们你想要完成什么吗?
标签: ios uitableview uitabbar