2013-05-02 37 views
-1

我使用此代碼通過網絡服務加載圖像和文字...能夠獲得文字,但不是圖像......任何人都可以幫助我......請通過網絡服務加載圖像和文字...能夠獲得文字,但不是圖像

NSString *append=[NSString stringWithFormat:@"%@",[[paiddic objectAtIndex:indexPath.row]objectForKey:@"grp_image_path"]]; 
NSString *myString = @"http://192.168.1.121/iptv_09042013/"; 
NSString *test = [myString stringByAppendingString:append]; 
NSString *str = [test stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
NSLog(@"%@",str); 
NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]]; 
UIImage* image1 = [UIImage imageWithData:imageData]; 
NSLog(@"Loaded Image: %@", image1); 

if (image1 == nil) 
{ 
    cell.photoView.image = [UIImage imageNamed:@"$.png"]; 
    // cell.titleLabel.text = [[paiddic objectAtIndex:indexPath.row]objectForKey:@"group_name"]; 
} 
else 
{ 
    cell.photoView.image = image1; 
} 
cell.titleLabel.text = [[paiddic objectAtIndex:indexPath.row]objectForKey:@"group_name"]; 
+0

是什麼NSLog的結果(@ 「%@」,STR); ? – 2013-05-02 10:30:21

+0

什麼是'photoView'? – 2013-05-02 10:38:16

回答

0

變化較小和檢查...

NSString *str = [append stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
    NSLog(@"%@",str); 
    NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]]; 
    UIImage* image1 = [UIImage imageWithData:imageData]; 
    NSLog(@"Loaded Image: %@", image1); 

    if (image1 == nil) 
    { 
     cell.photoView.image = [UIImage imageNamed:@"$.png"]; 
     // cell.titleLabel.text = [[paiddic objectAtIndex:indexPath.row]objectForKey:@"group_name"]; 
    } 
    else 
    { 
    cell.photoView.image = image1; 
    } 
    cell.titleLabel.text = [[paiddic objectAtIndex:indexPath.row]objectForKey:@"group_name"];