2014-07-27 31 views
0

我創建了一個應用程序來使用URL查看一些數據。我使用了asynctask來防止主線程阻塞。但是在加載頁面之後,我需要向下滾動並查看可見的圖像。但它不顯示每個圖像。這是我的代碼。需要滾動才能看到ios中的表格單元格中的圖像

viewDidLoad方法

​​

的cellForRowAtIndexPath方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *CellIdentifier = @"SettingsCell"; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell=[[UITableViewCell alloc]initWithStyle: 
      UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 
    Lawyer *l = [[Lawyer alloc]init]; 
    l = [_myObject objectAtIndex:indexPath.row]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%@" "%@",l.firstName,l.lastName]; 
    cell.detailTextLabel.text = l.state; 
    cell.imageView.image = l.uiImage; 

    return cell; 
} 

我該如何解決這個問題。

在此先感謝!

回答

0

請記住,您使用的是異步代碼,並且您在編輯器中看到的行的順序不一定是它將執行的順序。

有時,調用[_myObject addObject:[l init…]]l上的圖像被設置。其他時候,它會在該行被調用之前設置。

您正在啓動l兩次,一次使用[[Lawyer alloc] init],第二次使用initFromDictionary:方法。不要初始化它兩次。

在你的cellForRowAtIndexPath:也是,你啓動l兩次。不要這樣做。

我不認爲你清楚什麼是指針和實例。清理你的基礎知識。

0

這聽起來像你可以使用SDWebImage。這會將您的所有異步處理爲UImageView上的類別。我的假設是,未顯示圖像的問題與代碼的asynctask部分有關。或者,您可以查看SDWebImage來源,看看它是如何實現同樣的事情的,如果您願意的話也可以重複。

相關問題