gpt4 book ai didi

ios - 如何在 UITableViewCell 上添加 rss 图片

转载 作者:行者123 更新时间:2023-11-29 03:23:37 26 4
gpt4 key购买 nike

我正在使用以下代码加载 RSS 提要。我可以知道如何将 RSS 中的小图像添加到 UITableViewCell 的左侧吗?非常感谢

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [stories count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifier";

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

// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[cell setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
cell.textLabel.font = [UIFont fontWithName:@"Heiti TC Light" size:16.0];
cell.textColor=[UIColor blackColor];//according to you.
cell.textLabel.numberOfLines = 3;
cell.backgroundColor = [UIColor clearColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"white.jpg"]];
self.tableView.backgroundColor = [UIColor clearColor];
return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic

int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];

// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"link: %@", storyLink);
// open in Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}


- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

if ([stories count] == 0) {
NSString * path = @"http://www.medworm.com/rss/medicalfeeds/source/Nature.xml";
[self parseXMLFileAtURL:path];
}

cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}

最佳答案

希望对您有所帮助。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 5, 158/2, 99/2) ];
//SDWebImage Extension
[imgView setImageWithURL:[NSURL URLWithString:@"http://www.yoururl.com/yourimage.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[self.contentView addSubview:imgView];
}
return cell;
}

关于ios - 如何在 UITableViewCell 上添加 rss 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20765718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com