RSS解析错误iPhone



我正在构建一个包含RSS阅读器的东西。一切似乎都很好,除了在每个描述中(使用下面的代码从RSS提要中获取),在描述之前,都有一个"

"我该如何删除它?

#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:@"nn"]
     ];
    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

这是MasterViewController.m文件的代码,该文件显示RSS提要:

#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

你知道发生了什么吗?

替换以下代码:

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

带有:

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

最新更新