2013-12-09 63 views
0

我试图使用递归表格视图,但当我单击到任何单元格时,出现第二个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 
+3

您将RSTableViewController的新实例推入导航堆栈,并将其委托设置为当前实例?我无法想象这是如何工作的。 –

+0

我在'tableView:didSelectRowAtIndexPath:'中缺少tableView数据源,所以现在它的工作原理! 'rsTableView.tableView.dataSource =自我;' – bianco

回答

0

A.[self.navigationController pushViewController:rsTableView animated:TRUE]是错误的,有没有这样的东西TRUE,这里只有YES

B.我觉得你做的事情非常错误的,但无论如何,你的方法应该是以下几点:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
    RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain]; 
    // each rs table view instance is it's own delegate and datasource 
    rsTableView.tableView.delegate = rsTableView; 
    // you forgot to add this line: 
    rsTableView.tableView.dataSource = rsTableView; 
    [self.navigationController pushViewController:rsTableView animated:YES]; 
    // what's this line for ?? the new ViewController will automatically call all the necessary methods. please remove it. 
    [tableView reloadData]; 
} 

请检查语法,其次,什么是RSTableViewController基地的ViewController?是UITableViewController? 确保你正确地设置委托和数据源。

+1

一个:在这种情况下TRUE或YES都是可用 B:是的,我是缺少的tableview数据源 是,'[的tableView reloadData]'是没有必要的 – bianco

+0

是,的UITableViewController是RSTableViewController的基类 感谢您的帮助! – bianco

+0

嗯有趣,这是我第一次看到TRUE :) – Nour1991