[英]How to add a tableView into a CellView in objective c?
I want show a tableView into a cell like: 我想在一个单元格中显示一个tableView:
_____________________________________
| (IMAGE) ______________ | --CELL 0
| | MyCustomText|--CELL 0.0 |
| |_____________| |
| |MyCustomText2|--CELL 0.1 |
| |_____________| |
| |
| |
--------------------------------------
_____________________________________
| (IMAGE) 2 | --CELL 1
--------------------------------------
I'm trying add a tableView in storyboard and then connect with a new TableviewController and with a new CustomCellTableView, but this not show anything in the row's table. 我正在尝试在情节提要中添加tableView,然后与新的TableviewController和新的CustomCellTableView连接,但这在行表中未显示任何内容。
It's possible? 这是可能的? How can I declare the viewController or needn't add ViewController? 如何声明viewController或不需要添加ViewController?
Thanks! 谢谢!
I think you don't need a new tableview controller. 我认为您不需要新的tableview控制器。 In your table cell, you can add another tableview. 在表格单元格中,您可以添加另一个表格视图。
@interface ImageCell : UITableViewCell<UITableViewDataSource,UITableViewDelegate>
@property (retain, nonatomic) IBOutlet UITableView *abc;
@end
and implement datasource and delegate method as usual. 并照常实现数据源和委托方法。
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == self.tableView) {
return 8;
} else {
return 3;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (tableView == self.tableView) {
cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
if (indexPath.row == 0) {
self.childTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 100)];
self.childTableView.delegate = self;
self.childTableView.dataSource = self;
[cell.contentView addSubview:self.childTableView];
}else {
cell.textLabel.text = @"Pavan";
}
} else if (tableView == self.childTableView){
cell = [self.tableView dequeueReusableCellWithIdentifier:@"childCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"childCell"];
}
cell.textLabel.text = @"hi";
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
if (indexPath.row == 0) {
return 250;
} else {
return 100;
}
} else {
return 50;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.