将行文本插入变量 [英] insert row text into variable

查看:205
本文介绍了将行文本插入变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSString *stalklabel = ;

NSURL *url = [NSURL URLWithString:@"http://news.search.yahoo.com/rss?ei=UTF-8&p=%@&fr=news-us-ss", stalklabel];

我有上面的代码,我需要知道如何获取行的值用户按下 stalklabel 。我使用Core Data填充表;

I have the code above, and I need to know how to get the value of the row that the user pressed into stalklabel. I use Core Data to fill the table; does that complicate things?

编辑:

澄清:

我在view1中有这个:

I have this in 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相关数据;

so when the user presses the row and gets sent to view2, view2 uses another class to fill the view. My original code with the URL resides in the other class. So I need to transfer the row text value to a variable in the other class and insert it into the URL so I can fill view2 with relevant data; does that make sense?

推荐答案

如果一个单元格被选中,tabelView将调用其委托方法 tableView:didSelectRowAtIndexPath:

If a cell gets selected, it tabelView will call its delegate method tableView:didSelectRowAtIndexPath:

如果您使用 fetchedResultsController (并且您应该使用CoreData),您只需执行

You get the indexPath. If you use a fetchedResultsController (and you should with CoreData), you can simply do

YourClass *object = (YourClass *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
NSString *aString = object.text;

请参阅 CoreDataBooks示例代码

编辑

关于你的代码,你似乎有一个超级AppDelegate。这不是必需的。

edit
Regarding your code you seem to have a "Super-AppDelegate". That is not needed.

您的NewsDetailViewController应该有一个属性指向对象。如新闻

Your NewsDetailViewController should have a property to point on the object. like 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];    
}

-viewDidLoad:您的NewsDetailViewController,您可以使用您的新闻对象的数据设置视图。

In the -viewDidLoad: of your NewsDetailViewController you can setup your view with the data from your news object.

这篇关于将行文本插入变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆