Question

I am building something that includes an RSS reader. Everything seems to work fine, except in every description (grabbed from the RSS feed using the code below), before the description, there is a "

" How do I remove that?

#import "RSSItem.h"
#import "GTMNSString+HTML.h"

@implementation RSSItem
-(NSAttributedString*)cellMessage
{
    if (_cellMessage!=nil) return _cellMessage;

    NSDictionary* boldStyle = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica-Bold" size:16.0]};
    NSDictionary* normalStyle = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:16.0]};

    NSMutableAttributedString* articleAbstract = [[NSMutableAttributedString alloc] initWithString:self.title];

    [articleAbstract setAttributes:boldStyle
                             range:NSMakeRange(0, self.title.length)];

    [articleAbstract appendAttributedString:
     [[NSAttributedString alloc] initWithString:@"\n\n"]
     ];
    int startIndex = [articleAbstract length];

    NSString* description = [NSString stringWithFormat:@"%@<p><p><em>...", [self.description substringToIndex:200]];
    description = [description gtm_stringByUnescapingFromHTML];
    [articleAbstract appendAttributedString:
     [[NSAttributedString alloc] initWithString: description]
     ];

    [articleAbstract setAttributes:normalStyle
                             range:NSMakeRange(startIndex, articleAbstract.length - startIndex)];

    _cellMessage = articleAbstract;
    return _cellMessage;
}

@end

And this is the code for the MasterViewController.m file which displays the RSS feed:

#import "MasterViewController.h"
#import "DetailViewController.h"
#import "TableHeaderView.h"
#import "RSSLoader.h"
#import "RSSItem.h"
@interface MasterViewController () {
    NSArray *_objects;
    NSURL* feedURL;
    UIRefreshControl* refreshControl;
}
@end
@implementation MasterViewController
-(void)refreshFeed
{
    RSSLoader* rss = [[RSSLoader alloc] init];
    [rss fetchRssWithURL:feedURL
                complete:^(NSString *title, NSArray *results) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [(TableHeaderView*)self.tableView.tableHeaderView setText:title];
                        _objects = results;
                        [self.tableView reloadData];
                        [refreshControl endRefreshing];

                    });
                }];
}


-(void)viewDidLoad
{
    [super viewDidLoad];
    feedURL = [NSURL URLWithString:@"http://pipes.yahoo.com/pipes/pipe.run?_id=c47dcdc375e72c5ad08f3470eea6afa0&_render=rss"];
    refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self
                       action:@selector(refreshInvoked:forState:)
             forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview: refreshControl];
    [self refreshFeed];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RSSItem *item = [_objects objectAtIndex:indexPath.row];
    CGRect cellMessageRect = [item.cellMessage boundingRectWithSize:CGSizeMake(200,10000)
                                                            options:NSStringDrawingUsesLineFragmentOrigin
                                                            context:nil];
    return cellMessageRect.size.height;
}
-(void) refreshInvoked:(id)sender forState:(UIControlState)state {
    [self refreshFeed];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    RSSItem *object = _objects[indexPath.row];
    cell.textLabel.attributedText = object.cellMessage;
    cell.textLabel.numberOfLines = 5;
    return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        RSSItem *object = _objects[indexPath.row];
        self.detailViewController.detailItem = object;
    }
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSDate *object = _objects[indexPath.row];
        [[segue destinationViewController] setDetailItem:object];
    }
}

-(IBAction)btn_regPressed:(id)sender
{
    NSLog(@"start to dissmis modal");
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

Any ideas what is happening?

Was it helpful?

Solution

Replace the following code:

NSString* description = [NSString stringWithFormat:@"%@<p><p><em>...", [self.description substringToIndex:200]];

With:

NSString* description = [[NSString stringWithFormat:@"%@<p><p><em>...", [self.description substringToIndex:200]] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top