简体   繁体   English

在类型的对象上找不到属性

[英]property not found on object of type

this seems just bizarre as i am not able to resolve it and stuck over it. 这似乎很奇怪,因为我无法解决它并坚持下去。 I am using storyboard to navigate between tableview and a detailview. 我正在使用故事板在tableview和detailview之间导航。 It was working fine when i was passing a single (NewsRecord) object from my tableview class(TopStoriesViewController) to my detail class(DetailNewsViewController). 当我将一个(NewsRecord)对象从我的tableview类(TopStoriesViewController)传递给我的详细类(DetailNewsViewController)时,它工作正常。 But now i need to pass an array of (NewsRecord) objects when moving to the detail class instead of a single (NewsRecord) object. 但是现在我需要在移动到detail类而不是单个(NewsRecord)对象时传递一个(NewsRecord)对象数组。 But when i create a NSArray * in my detail class and try to access it in my tableview class in prepareForSegue method using the object of detail class it gives the following error---property 'items' not found on object of type 'DetailNewsViewController *' at compile time. 但是当我在我的detail类中创建一个NSArray *并尝试使用detail类的对象在prepareForSegue方法的tableview类中访问它时,它会给出以下错误---在'DetailNewsViewController类型的对象上找不到属性'items' '在编译时。 items is a NSArray object which get its contents from the 'entries' which is also an NSArray in TopStoriesViewController class. items是一个NSArray对象,它从'entries'获取其内容,该条目也是TopStoriesViewController类中的NSArray。

My question is why am i able to access getNewsDetails of DetailNewsViewController in TopStoriesViewController and not items. 我的问题是为什么我能够访问TopStoriesViewController中的DetailNewsViewController的getNewsDetails而不是项目。

My classes are as follows - TopStoriesViewController.m 我的课程如下 - 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 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 DetailNewsViewController.m

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

NewsRecord.h NewsRecord.h

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

You should try to explicitely use the setter for items: 您应该尝试明确使用项目的setter:

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

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

     }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM