4

这似乎很奇怪,因为我无法解决它并坚持下去。我正在使用情节提要在 tableview 和 detailview 之间导航。当我将单个(NewsRecord)对象从我的 tableview 类(TopStoriesViewController)传递到我的详细信息类(DetailNewsViewController)时,它工作正常。但是现在我需要在移动到详细信息类而不是单个(NewsRecord)对象时传递一个(NewsRecord)对象数组。但是,当我在我的详细信息类中创建一个 NSArray * 并尝试使用详细信息类的对象在 prepareForSegue 方法中的我的 tableview 类中访问它时,它会给出以下错误---在 'DetailNewsViewController * 类型的对象上找不到属性'项目' ' 在编译时。items 是一个 NSArray 对象,它从“条目”中获取其内容

我的问题是为什么我能够在 TopStoriesViewController 而不是项目中访问 DetailNewsViewController 的 getNewsDetails。

我的课程如下 - TopStoriesViewController.m

#import "DetailNewsViewController.h"

     some code here....

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
         if ([[segue identifier] isEqualToString:@"ShowDetailedNews"]) {
         DetailNewsViewController *detailNewsVC = [segue destinationViewController];
         [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
         NSInteger indexForNewsSelectedFromTBV = [[self.tableView indexPathForSelectedRow] row];
         [detailNewsVC setGetNewsDetails:[entries objectAtIndex:indexForNewsSelectedFromTBV]]; //This is working fine...
         detailNewsVC.items=entries;  //Error is occurring here...
    }
   } 

DetailNewsViewController.h

#import "NewsRecord.h"
    @interface DetailNewsViewController : UIViewController {
       NewsRecord *getNewsDetails;

       some other declarations...

       NSArray *items;
   }
@property(nonatomic,retain) NewsRecord *getNewsDetails;
@property(nonatomic,retain) NSArray *items;
@end

DetailNewsViewController.m

#import "DetailNewsViewController.h"
@synthesize getNewsDetails,items;

新闻记录.h

@interface NewsRecord : NSObject {
      NSString *newsTitle;
      NSString *newsDescription;
    }
    @property(nonatomic,retain) NSString *newsTitle;
    @property(nonatomic,retain) NSString *newsDescription;
    @end
4

1 回答 1

0

您应该尝试明确地使用设置器来获取项目:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     if ([[segue identifier] isEqualToString:@"ShowDetailedNews"]) 
     {

     DetailNewsViewController *detailNewsVC = [segue destinationViewController];
    ...
     [detailNewsVC setItems:entries];

     }
} 
于 2012-02-13T12:30:52.280 回答