Question

I am using the following code to load the RSS feed. May I know how can i add a small image from the RSS to the left hand side of the UITableViewCell? Many Thanks

- (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);
}
Was it helpful?

Solution

I hope this will be helpful.

- (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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top