2012-10-22 28 views
0

我有一個UITableView加載一些鳴叫,所有的作品很好,但是當我填充表時,它不會進入到CellForRow方法,直到我觸摸表視圖....有人知道如何解決這個問題嗎?爲什麼UITableView在我觸摸時顯示數據?

tab = [[UITableView alloc] initWithFrame:CGRectMake(10, 300, 400, 200) style:UITableViewStylePlain]; 
tab.dataSource = self; 
tab.delegate = self; 

然後...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"entra a cellula"); 
    Tweet *t = [tweets objectAtIndex:indexPath.row]; 

    static NSString *MyIdentifier = @"MyIdentifier"; 

    // Try to retrieve from the table view a now-unused cell with the given identifier. 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    // If no cell is available, create a new one using the given identifier. 
    if (cell == nil) { 
     // Use the default cell style. 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier]; 
    } 



    cell.textLabel.text = t.screenName; 
    cell.detailTextLabel.text = t.text; 
    cell.imageView.image = t.profileImage; 
return cell; 

}

+0

哪裏代碼添加tableview中作爲一個子視圖? – hukir

+0

緊跟在tab.delegate = self指令之後... [self addSubview:tab];然而,表顯示,但無效......只是當我觸摸它,它是填充... –

+0

你是否正在加載與後臺線程這些鳴叫? – ohr

回答

1

基於我們所知道的是,您不會將表添加爲主線程的子視圖。這意味着在您滾動之前不會進行重繪。嘗試在GCD呼叫,像這樣的包裝通話addsubview:

dispatch_async(dispatch_get_main_queue(), ^() { 
    [self addSubview:tab]; 
}); 
+0

yeap我剛剛用這個函數解決了它幾秒鐘...但是正確的答案:) –

0

當你加載完你的鳴叫調用這個方法:

[tab reloadData]; 

刷新你的tableView數據源。

+0

正如我所說的推文當我創建並填充表格時已經收費... –