2013-01-10 38 views
1

我有一個主 - 細節應用程序。我列出了MasterViewController tableview中應用程序文檔文件夾中的所有圖像。在單擊每個tableview項目時,我在DetailViewController中加載圖像,該圖像具有UIImageView。我面臨的問題是,當我點擊一個tableview項目時,圖像不會在第一個實例中加載。我只是在DetailViewController中看到消息「Detail view content goes here」。如果我回去再試一次,它會工作得很好。它只是圖像不會加載的第一次。在DetailViewController的第一個實例中不加載UIImage

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (!self.detailViewController) { 
    self.detailViewController = [[PtmDetailViewController alloc] initWithNibName:@"PtmDetailViewController" bundle:nil]; 
} 
//NSDate *object = _objects[indexPath.row]; 

NSData *imgData = [NSData dataWithContentsOfFile:self.fPath]; 
UIImage *thumbNail = [[UIImage alloc] initWithData:imgData]; 
self.detailViewController.imgViewer.image = thumbNail; 
[self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 

我在做什麼錯?任何幫助,將不勝感激。

回答

0

看起來好像detailViewController的視圖沒有時間加載。因此,您將圖像設置爲nil UIImageView(尚未初始化)。

嘗試添加屬性UIImage *thumbdetailViewController然後在detailViewController的viewDidLoad添加

​​

而在你tableView:didSelectRowAtIndexPath:變化

UIImage *thumbNail = [[UIImage alloc] initWithData:imgData]; 
self.detailViewController.imgViewer.image = thumbNail; 

UIImage *thumbNail = [[UIImage alloc] initWithData:imgData]; 
self.detailViewController.thumb = thumbNail; 
0

我想,第一次EIT她self.fpath即將nil或在那path沒有圖像。檢查imgData第一次有valur or nil。然後顯示你的圖片,

[UIImage imageWithContentsOfFile:self.fpath] 
相關問題