NSString *stalklabel = ;
NSURL *url = [NSURL URLWithString:@"http://news.search.yahoo.com/rss?ei=UTF-8&p=%@&fr=news-us-ss", stalklabel];
我有上面的代码,我需要知道如何获取用户按下stalklabel
的行的值。我使用核心数据来填补表格;这会使事情变得复杂吗?
编辑:
抱歉;澄清:
我在view1中有这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];
//[self.appDelegate loadNewsDetails];
NewsDetailViewController *newsDetail = [[NewsDetailViewController alloc] initWithNibName:@"NewsDetailViewController" bundle:nil];
//NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// ...
// Pass the selected object to the new view controller.
//newsDetail.titleTextView.text = [[[self appDelegate] currentlySelectedBlogItem]title];
//newsDetail.descriptionTextView.text = [[[self appDelegate] currentlySelectedBlogItem]description];
[self.navigationController pushViewController:newsDetail animated:YES];
[newsDetail release];
}
所以当用户按下该行并被发送到view2时,view2使用另一个类来填充视图。带有URL的原始代码位于另一个类中。所以我需要将行文本值传递给另一个类中的变量并将其插入到URL中,以便我可以用相关数据填充view2;这有意义吗?
答案 0 :(得分:1)
使用stringWithFormat:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://news.search.yahoo.com/rss?ei=UTF-8&p=%@&fr=news-us-ss", stalklabel]];
答案 1 :(得分:1)
如果某个单元格被选中,它的tabelView将调用其委托方法tableView:didSelectRowAtIndexPath:
您获得indexPath。如果您使用fetchedResultsController
(并且您应该使用CoreData),则只需执行
YourClass *object = (YourClass *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
NSString *aString = object.text;
修改强>
关于你的代码,你似乎有一个“Super-AppDelegate”。这不是必需的。
你的NewsDetailViewController应该有一个属性指向对象。比如news
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NewsDetailViewController *newsDetail = [[NewsDetailViewController alloc] initWithNibName:@"NewsDetailViewController" bundle:nil];
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
newsDetail.news = selectedObject;
[self.navigationController pushViewController:newsDetail animated:YES];
[newsDetail release];
}
在NewsDetailViewController的-viewDidLoad:
中,您可以使用新闻对象中的数据设置视图。