2015-11-12 65 views
3

我一直在撞牆,因爲我以爲我在stackoverflow上嘗試了所有可能的東西。重新加載數據未調用cellForRowAtIndexPath:

所以目前我創建一個表像這樣

- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath: (NSIndexPath *)indexPath { 
    NSLog(@"CHECK IF THIS IS CALLED"); 
    static NSString *CellIdentifer = @"CellIdentifier"; 
    CBPeripheral *placeHolder; 

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifer]; 
    // Using a cell identifier will allow your app to reuse cells as they come and go from the screen. 
    if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifer]; 
    } 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     placeHolder = _connectedPeripherals[indexPath.row]; 
     cell.textLabel.text = placeHolder.name; 
    } 
    return cell; 
} 

,我從我調用另一個函數調用[self.tableView reloadData]。我知道它在該函數中被調用,但cellForRowAtIndexPath不會再被調用。

我創建了一個UITableView財產在我的.h文件 @property (strong, nonatomic) UITableView *tableView;

而創建的表像這樣

self.tableView = [[UITableView alloc] init]; 
self.tableView.rowHeight = 60.0f; 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 



self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 
[self.view addSubview:self.tableView]; 
[self.view addConstraints:@[ [HTConstraints leftAlignView:self.tableView 
               toView:self.view 
              withSpacing:5], 

          [HTConstraints topAlignView:self.tableView 
               toView:self.view 
              withSpacing:5], 

          [HTConstraints rightAlignView:self.tableView 
                toView:self.view 
              withSpacing:5], 

          [HTConstraints bottomAlignView:self.tableView 
                toView:self.view 
               withSpacing:5], 
          ]]; 

到目前爲止,我已經試過了確保[self.tableView reloadData]是被稱爲在主線程。確保我的部分沒有返回0

編輯 這是我reloadData功能,並通過[[RootViewController sharedInstance] reloadData];和日誌打印調用另一個類 當我打電話吧。

- (void)reloadData { 
    NSLog(@"Reloading"); 
    [self.tableView reloadData]; 
} 
+0

更新與具有調用'reloadData'方法您的問題之後。解釋何時以及如何調用該方法。 – rmaddy

+0

@rmaddy完成!!!! – user3281743

+0

如何在主線程上調用reloadData? –

回答

-1

設置一個斷點內 - (無效)reloadData或嘗試添加您的UITableView數據源的數量在你的NSLog。

通常cellForRowAtIndexPath沒有得到調用,因爲它沒有任何顯示。

-1

我看到,在您的代碼中,您忘記將tableView作爲子視圖添加到控制器。 添加下面的代碼您的tableView的初始化

[self.view addSubview:tableView]; 
+0

對不起,我看到你做到了。也許檢查你的'tableView'的框架,如果你的'tableView'的高度等於零,它也會導致問題 – Shamsiddin

相關問題