开发者

Cant set row selected for RSS app in iphone

开发者 https://www.devze.com 2023-01-24 09:17 出处:网络
OK, i\'m making an app that pulls down rss feeds, the initial table view is the headlines, the second view shows the detail of that headline the user selected.

OK, i'm making an app that pulls down rss feeds, the initial table view is the headlines, the second view shows the detail of that headline the user selected.

This is the code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];

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

}

setCurrentlySelectedBlogItem is a pointer to blogrss class which is reference in the AppDelegate. When i'm clicking on the row of the headline and its taking me to the next view, the content is empty. In the last two lines above i'm attempting to set the UILabel's as the current headline's details...

Anyone hazard a guess to why this is happening?

Also this is my AppDelegate.h file:

    #import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@class RssFunViewController;
@class NewsDetailViewController;
@class RootViewController;
@class BlogRss;
@class BlogRssParser;

@interface ExampleAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
    RootViewController *viewController;
    NewsDetailViewController * newsDetailC开发者_运维技巧ontroller;
    BlogRss * currentlySelectedBlogItem;

@private
    NSManagedObjectContext *managedObjectContext_;
    NSManagedObjectModel *managedObjectModel_;
    NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RootViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet NewsDetailViewController * newsDetailController;

@property (readwrite,retain) BlogRss * currentlySelectedBlogItem;

@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (NSString *)applicationDocumentsDirectory;
- (void)saveContext;

@end


The UILabels in the view controller are probably still nil at that point and not accessible. Instead of setting the controls directly, create two NSString properties in the NewsDetailViewController and set those before you push it. Then, in the NewsDetailViewController, set the labels to the property values in the viewDidLoad method (at which point the labels should be instantiated and accessible).

0

精彩评论

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