无法设置属性

时间:2016-03-08 12:13:49

标签: ios objective-c uiwebview

我正在制作博客阅读器应用。一切正常,直到我尝试从单元格访问detailView。我收到此错误,

[UINavigationController setPFeedURL:]: unrecognised selector sent to instance 0x7f96d5802800

下面的代码在PRTableViewController.m

#import "PRTableViewController.h"
#import "PRFeedPost.h"
#import "PRDetailViewController.h"

这是代码发生崩溃的地方

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([segue.identifier isEqualToString:@"showDetail"]){
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    PRFeedPost *feed_Post = [self.polisenFeed objectAtIndex:indexPath.row];
    [segue.destinationViewController   setPFeedURL:feed_Post.url];
    }
}

这是为了帮助您了解我尝试将PFeedURL设置为。也在PRViewTableController.m

  self.polisenFeed = [NSMutableArray array];

  NSArray *polisenFeedArray = [dataDictionary objectForKey:@"posts"];

for (NSDictionary *postDictionary in polisenFeedArray) {
    PRFeedPost *fp = [PRFeedPost feedWithTitle:[postDictionary objectForKey:@"title"]];
    fp.author = [postDictionary objectForKey:@"author"];
    fp.thumbnail = [postDictionary objectForKey:@"thumbnail"];
    fp.date = [postDictionary objectForKey:@"date"];
    fp.url = [NSURL URLWithString:[postDictionary objectForKey:@"url" ]];
    [self.polisenFeed addObject:fp];

}

现在是PRDetailViewController.h,

这是我试图设置的属性,

@property (strong, nonatomic) NSURL *pFeedURL;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIWebView *webView;

以下是PRDetailViewController.m中的代码,

- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.pFeedURL];
[self.webView loadRequest:urlRequest];

我似乎无法弄清楚为什么会崩溃。我知道这与这一行有关,

  [segue.destinationViewController   setPFeedURL:feed_Post.url];

(我认为这就是那条线。我无法弄清楚为什么我无法设置它。

感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

更改此

PRDetailViewController *objPRDetailViewController = (PRDetailViewController *)[segue.destinationViewController topViewController]; 
objPRDetailViewController.pFeedURL=feed_Post.url;     

并且还将以下代码放在viewDidAppear

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.pFeedURL];
[self.webView loadRequest:urlRequest];

答案 1 :(得分:1)

试试这个

[[((id)segue.destinationViewController) topViewController]   setPFeedURL:feed_Post.url];

让我知道它是否有效

豫ICP备18024241号-1