2012-03-04 17 views
0

私のXMLParserは正常に動作しており、問題なく必要なすべての要素を解析しています。なんらかの理由で、cellForRowAtIndexPathメソッドは、セルイメージをURLのイメージに設定しません。 tempUrl変数を画像付きのリンクに変更すると、それは正常に動作し、[[stories objectAtIndex: storyIndex] objectForKey:@"srcthumb"];コード行では機能しません。UITableViewはXMLファイルから画像をロードしません

私は上記のコード行をチェックしていて、問題なくコンソールに有効なURLを出力します。

私は間違っていますか?以下 は私のコードです:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"Header"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    } 

    // Set up the cell 
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 
    [cell.textLabel setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]]; 

    //NSString *tempURL = [[stories objectAtIndex: storyIndex] objectForKey:@"srcthumb"]; 

    NSString *tempURL =[[stories objectAtIndex: storyIndex] objectForKey:@"srcthumb"]; 

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:tempURL]]]; 



    cell.imageView.image = image; 

    return cell; 
} 

答えて

0

あなたが本当に使用する必要があり、これをデバッグするのを助けるために、あなたのtempURLにホワイトスペースや不正な文字がある可能性があります:

がある場合、これが表示されるはずですスペースや悪い文字。

これは私にとって起こりました。私はすべての空白のURLを取り除き、それらを( - )記号に置き換えなければなりませんでした。

の代わりに:​​

それは次のようになります。www.mysite.com/my-image.jpg

関連する問題