2012-10-11 68 views
2

我想解析UITableView中的圖像文本,我只能看到每行的文本,但我看不到圖像。Xcode解析RSS圖像的XML問題

這是我的代碼;

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

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [self.anaTablo dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 


    UILabel *textBaslik = (UILabel *) [cell viewWithTag:3]; 
    UIImage *imagePic = (UIImage *) [cell viewWithTag:7]; 

    textBaslik.text =[titleArray objectAtIndex:indexPath.row]; 
    imagePic.images = [imageArray objectAtIndex:indexPath.row]; 

return cell; 

}

但它沒有工作和搜索我已經試過這之後;

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

    UILabel *textBaslik = (UILabel *) [cell viewWithTag:3]; 
    UIImage *imagePic = (UIImage *) [cell viewWithTag:7]; 

    textBaslik.text =[titleArray objectAtIndex:indexPath.row]; 

    NSString *str1 = [[NSString alloc] initWithFormat:@"%@", imageArray]; 

    NSData *bgImageData = [NSData dataWithContentsOfFile:str1]; 

    UIImage *img1 = [UIImage imageWithData:bgImageData]; 

    imagePic = [img1 objectAtIndex:indexPath.row]; 

return cell 

}

難道我做錯了什麼?我很新的Xcode

從現在開始感謝。

回答

3

我檢查你的代碼檢查該示例代碼和我更改了委託方法

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

以下

NSString *str1 = [[NSString alloc] initWithFormat:@"%@", imageArray]; 
NSData *bgImageData = [NSData dataWithContentsOfFile:str1]; 
UIImage *img1 = [UIImage imageWithData:bgImageData]; 

imagePic = [imageArray objectAtIndex:indexPath.row]; 

cell.imageView.image=imagePic; 

現在出現新錯誤,請檢查它

+0

我認爲它不會工作再次感謝。 –

+0

我的問題是這樣的 NSString * trimmedString = [imageLink.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; –

3

查看本教程中關於使用XMLParses解析RSS,它完美地工作。 Wiki XML parse data

你應該使用TBXML框架 TBXML parser

+0

我的RSS工作正常,我可以看到UItableView中的所有文本,但我無法解析這是我的問題的圖片。感謝您的鏈接,但它不能解決我的問題 –

+0

你是否得到了圖像的網址?檢查此鏈接,將回答您的問題http://stackoverflow.com/questions/7565123/load-image-to-a-tableview-from-url-iphone-sdk – Aitul

+0

是的,但它不會顯示任何東西 –