2013-12-09 67 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