在此先感謝。我在數組中獲取圖像URL。如何從數組中提取網址並在表視圖上顯示圖像
myarray = { "http://www.abc.com/uploads/sarab.jpg", .... };
現在我不知道如何訪問表視圖中的圖像?有沒有幫助的示例代碼?
在此先感謝。我在數組中獲取圖像URL。如何從數組中提取網址並在表視圖上顯示圖像
myarray = { "http://www.abc.com/uploads/sarab.jpg", .... };
現在我不知道如何訪問表視圖中的圖像?有沒有幫助的示例代碼?
把這個代碼的cellForRowAtIndexPath然後將正常工作:
NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[myarray objectAtIndex:indexPath.row]]];
cell.imageView.image=[UIImage imageWithData:imageData];
你應該做這個,
從陣列將這個代碼的cellForRowAtIndexPath獲取URL,這將幫助你..
NSString *str = [YOUR_ARR objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:str];
首先轉換網址NSData的分配,然後再數據你的形象..
NSData *imgData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imgData];
,之後
cell.imageView.image = image;
編碼愉快..
謝謝你幫我 –
下面的方式,就可以實現這一點:
NSString *strImageUrl = [myarray objectAtIndex:indexpath.row];
NSURL *url = [NSURL URLWithString: strImageUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
UIImageView *displayimage = [[UIImageView alloc] init];
[displayimage setImage:image];
讓我知道的情況下,任何困難。
乾杯
如果我有一些字符串和圖像的URL數組,那麼我怎麼能不使用索引號的獲取圖像URL陣列。像myarray = {「india」,123654,「http://www.abc.com/uploads/sarab.jpg」,..} –
我認爲你已經管理你的陣列很奇怪。如果字符串中存在「www」或「.jpg,.png」,則可以從數組中獲取對象,然後從字符串中檢查該對象。所以它會像URL一樣,你可以綁定你的圖片。 –
我的建議是創建NSObject類具有像標題,數字,ImageUrl(印度,123456,abc.com/uploads.srarb.jpg)屬性。並將這個類的對象添加到你的數組中。所以,你將通過使用「Index.Row」來獲得對象。然後你可以像使用classObject.ImageUrl一樣使用imageUrl。並做這個過程。希望你能得到答案。 –
謝謝你幫我.......問題就解決 –