Ios 解析rss提要并将字符串附加到link-objective c
我正在做一个项目,为每篇文章的标题、描述和链接解析rss提要。然后我需要在链接后面附加一个字符串@“?f=m” 我不知道从哪里开始。我对IOS编程还不熟悉。我想我需要处理的文件在这里:Ios 解析rss提要并将字符串附加到link-objective c,ios,objective-c,rss,Ios,Objective C,Rss,我正在做一个项目,为每篇文章的标题、描述和链接解析rss提要。然后我需要在链接后面附加一个字符串@“?f=m” 我不知道从哪里开始。我对IOS编程还不熟悉。我想我需要处理的文件在这里: -(void)viewDidAppear:(BOOL)animated { RSSItem* item = (RSSItem*)self.detailItem; self.title = item.title; webView.delegate = self; NSURLRequest* articleReq
-(void)viewDidAppear:(BOOL)animated
{
RSSItem* item = (RSSItem*)self.detailItem;
self.title = item.title;
webView.delegate = self;
NSURLRequest* articleRequest = [NSURLRequest requestWithURL: item.link];
webView.backgroundColor = [UIColor clearColor];
[webView loadRequest: articleRequest];
}
但也可能在这里:
-(void)fetchRssWithURL:(NSURL*)url complete:(RSSLoaderCompleteBlock)c
{
dispatch_async(kBgQueue, ^{
//work in the background
RXMLElement *rss = [RXMLElement elementFromURL: url];
RXMLElement* title = [[rss child:@"channel"] child:@"title"];
NSArray* items = [[rss child:@"channel"] children:@"item"];
NSMutableArray* result = [NSMutableArray arrayWithCapacity:items.count];
//more code
for (RXMLElement *e in items) {
//iterate over the articles
RSSItem* item = [[RSSItem alloc] init];
item.title = [[e child:@"title"] text];
item.description = [[e child:@"description"] text];
item.link = [NSURL URLWithString: [[e child:@"link" ] text ]] ;
[result addObject: item];
}
c([title text], result);
});
}
衷心感谢您的帮助。您只需按以下方式添加参数:
NSString *modifiedString = [NSString stringWithFormat:@"%@%@",[item.link absoluteString],@"?f=m"];
NSURL *modifiedUrl = [NSURL URLWithString:modifiedString];
现在使用modifiedUrl而不是item.link既然您要添加字符串文字,为什么要使用
stringWithFormat:
?为什么不简单地使用NSString*modifiedString=[[item.link absoluteString]stringByAppendingString:@?f=m“]代码>@rmaddy:thx-maddy。你也可以用这个。但是我通常使用这种方法,我找不到它们之间有什么巨大的区别。它是有效的。请记住,stringWithFormat:
比简单的字符串追加效率低得多。对于这样的一行来说,这并不重要。另一个选择是将格式中的第二个%@
替换为实际文本,因为它是文本。非常感谢大家,我真诚地感谢你们的帮助。很好的学习经验。它很有效:)我真诚地感谢你的帮助。非常非常感谢。如果可以的话,我会投赞成票的。