【问题标题】:Xcode parsing RSS XML with images issueXcode 解析带有图像问题的 RSS XML
【发布时间】:2012-10-02 05:40:10
【问题描述】:

我正在尝试用 UITableView 中的图像解析文本,我只能看到每一行的文本,但看不到图像。

这是我的代码;

- (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 的新手

从现在开始谢谢。

【问题讨论】:

    标签: xcode uitableview xml-parsing uiimageview nsdata


    【解决方案1】:

    我检查你的代码并更改以下内容

    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;
    

    在委托方法中

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

    现在出现一个新错误,检查一下

    【讨论】:

    • 我的问题也是这个 NSString *trimmedString = [imageLink.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    【解决方案2】:

    查看这篇关于使用 XMLParses 解析 RSS 的教程,它运行良好。 Wiki XML parse data

    您应该使用 TBXML 框架检查此示例代码 TBXML parser

    【讨论】:

    • 我的 RSS 工作正常,我可以看到 UItableView 中的所有文本,但我无法解析我的问题的图片。感谢您的链接,但它不能解决我的问题
    • 你得到图片的网址了吗?检查此链接将回答您的问题stackoverflow.com/questions/7565123/…
    • 你必须以异步方式从 url 下载图像(更好)。试试苹果示例 Lazy tableviews,这是一个很好的起点developer.apple.com/library/ios/#samplecode/LazyTableImages/…
    • 感谢 Aitul 的帮助,但这对 mw 来说很难,有没有更简单的方法?我可以与您分享我的代码,我的代码非常简单。
    • 这里有一个简单的例子来理解它:blog.mugunthkumar.com/coding/…如果答案有趣,请投票给我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    相关资源
    最近更新 更多