我試圖使用遞歸表格視圖,但當我單擊到任何單元格時,出現第二個UITableView(由tableView:didSelectRowAtIndexPath創建),只有空行沒有任何文本。遞歸調用UITableView單元格爲空
有人可以幫忙嗎?
@implementation RSTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self.tableView registerClass:[RSCell class] forCellReuseIdentifier:@"bbaCell"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain];
rsTableView.tableView.delegate = self;
[self.navigationController pushViewController:rsTableView animated:TRUE];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"bbaCell";
RSCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.label1.text = [self.array objectAtIndex:indexPath.row];
cell.label2.text = [self.array objectAtIndex:indexPath.row];
return cell;
}
@end
您將RSTableViewController的新實例推入導航堆棧,並將其委託設置爲當前實例?我無法想象這是如何工作的。 –
我在'tableView:didSelectRowAtIndexPath:'中缺少tableView數據源,所以現在它的工作原理! 'rsTableView.tableView.dataSource =自我;' – bianco