【问题标题】:property not found on object of type在类型的对象上找不到属性
【发布时间】:2012-03-04 17:28:10
【问题描述】:

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

【问题讨论】:

  • 尝试,清理项目然后重新构建
  • 如果 dat 不起作用,请清理你的项目,重新启动你的 xcode....
  • @Krrish,@Inder Kumar Rathore:尝试清理和删除派生数据...仍然没有得到解决
  • 你能复制粘贴显示的确切错误吗
  • @Krrish:在“DetailNewsViewController *”类型的对象上找不到属性“项目”

标签: objective-c ios5 xcode4.2 uistoryboard


【解决方案1】:

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

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

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

     }
} 

【讨论】:

  • 感谢您的回答。我的 items 数组确实填充了 objects 数组。我觉得这会起作用。但是你能告诉我为什么 xcode 会抛出警告“DetailNewsViewController 可能无法响应'setItems'”,而之前当我使用“setGetNewsDetails”来设置我的对象时,我没有收到任何警告。为什么 detailNewsVC.items 会抛出错误。
猜你喜欢
  • 2014-04-27
  • 1970-01-01
  • 2023-03-22
  • 2019-06-25
  • 2021-06-30
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多