我正在构建包含 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:@"\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
这是显示 RSS 提要的 MasterViewController.m 文件的代码:
#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
任何想法发生了什么?