我創建了一個名爲myclass的基於視圖的項目。在imageview中顯示圖像時出現問題
我添加了另一個UIviewcontroller子類給它,命名爲webdata。
在webdataviewcontroller.m我從網絡服務器獲取圖像。
我需要從webdataViewController.m
這個我在webdataViewController.m代碼myclassViewController.m顯示在imageview的這個形象是
docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
imagepath = [NSString stringWithFormat:@"%@/image.png",docDir];
logopath = [NSString stringWithFormat:@"%@/logo.png",docDir];
myclassViewController *obj = [[myclassViewController alloc]init];
obj.homeimage.image = [UIImage imageWithContentsOfFile:imagepath];
但不顯示圖像,我嘗試打印在控制檯
NSLog(@"image to display %@",obj.homeimage.image);
NSLog(@"image to display %@",[UIImage imageWithContentsOfFile:imagepath]);
圖像,但我得到這樣
image to display (null)
image to display <UIImage: 0x6f614b0>
爲什麼我得到null爲obj.homeimage.image,我沒有得到任何一個請幫助我。
謝謝你的愛戴。
(讓我補充評論,如果問題是不理解)
您應該使用'stringByAppendingPathComponent:'來創建路徑。 – fabian789 2011-02-27 09:36:32