2011-05-11 31 views
0

我想顯示的UITableViewCell, 圖像,在UITableView中我的數據是從web服務 取我用xmlparsing爲 即iphone-webservice的圖像

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 
} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
} 

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{ 
} 

現在,如果我的XML輸出繼電器返回映像路徑名稱,,

像HHTP://www.abc.com/a.png

然後uitableviewcell可以顯示圖像嗎?

如果沒有,那麼我怎麼能顯示圖像...

回答

0
id path = @"http://www.abc.com/a.png"; 
NSURL *url = [NSURL URLWithString:path]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 
UIImage *img = [[UIImage alloc] initWithData:data cache:NO] 
cell.imageView.image = img; 
1
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.abc.com/a.png"]]; 
    UIImage *img = [[UIImage alloc] initWithData:data]; 
    cell.imageView.image = img; 
    [img release]; 
    [data release]; 
+0

如果圖像是大,你可能希望將其加載到一個線程,並顯示出UIActivityIndi​​cator,直到它的加載,但高雅的代碼應該管用。 – 2011-05-11 08:27:20

+0

是啊...絕對是真的......但我假設你的圖像是小的,因爲你要在tableviewcell中顯示它們,還有一件事如果你的行很大,那麼你可以使用延遲加載。 – 2011-05-11 08:29:58