开发者

insert row text into variable

NSString *stalklabel = ;

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

I have the code above, and I need to know how to get the value of the row that the user p开发者_Python百科ressed into stalklabel. I use Core Data to fill the table; does that complicate things?

EDIT:

Sorry; to clarify:

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];   
}

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?


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

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;

See the CoreDataBooks example code

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

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];    
}

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


Use stringWithFormat:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜