在该类型的对象上找不到属性
这看起来很奇怪,因为我无法解决它并坚持下去。我正在使用故事板在表格视图和详细视图之间导航。当我将单个(NewsRecord)对象从我的表视图类(TopStoriesViewController)传递到我的详细信息类(DetailNewsViewController)时,它工作正常。但现在我需要在移动到详细信息类时传递一组 (NewsRecord) 对象,而不是单个 (NewsRecord) 对象。但是,当我在详细信息类中创建 NSArray * 并尝试使用详细信息类的对象在prepareForSegue方法中的tableview类中访问它时,会出现以下错误——在“DetailNewsViewController *”类型的对象上找不到属性“items” ' 在编译时。 items 是一个 NSArray 对象,它从“entries”获取其内容,“entries”也是 TopStoriesViewController 类中的 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;
NewsRecord.h
@interface NewsRecord : NSObject {
NSString *newsTitle;
NSString *newsDescription;
}
@property(nonatomic,retain) NSString *newsTitle;
@property(nonatomic,retain) NSString *newsDescription;
@end
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. It was working fine when i was passing a single (NewsRecord) object from my tableview class(TopStoriesViewController) to my detail class(DetailNewsViewController). But now i need to pass an array of (NewsRecord) objects when moving to the detail class instead of a single (NewsRecord) object. 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. items is a NSArray object which get its contents from the 'entries' which is also an NSArray in TopStoriesViewController class.
My question is why am i able to access getNewsDetails of DetailNewsViewController in TopStoriesViewController and not items.
My classes are as follows -
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;
NewsRecord.h
@interface NewsRecord : NSObject {
NSString *newsTitle;
NSString *newsDescription;
}
@property(nonatomic,retain) NSString *newsTitle;
@property(nonatomic,retain) NSString *newsDescription;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试明确地使用项目的设置器:
You should try to explicitely use the setter for items: