我有一个如下所示的课程。
#import <Foundation/Foundation.h>
@interface JAMToDoItem : NSObject
@property(nonatomic,strong) NSString *itemName;
@property BOOL * completed;
@property (readonly) NSDate * CreactionDate;
//-(void)MarkAsCompleted:(BOOL)IsComplete onDate:(NSDate*)date;
@end
JAMToDoItem.m文件
//
// JAMToDoItem.m
// ToDoList
//
// Created by juanabreu on 2/15/14.
// Copyright (c) 2014 juanabreu. All rights reserved.
//
#import "JAMToDoItem.h"
@interface JAMToDoItem()
//@property NSDate *completionDate;
@end
@implementation JAMToDoItem
@end
然后我尝试访问此类中的属性,如下所示,我得到一个错误
//
// JAMToDoList.m
// ToDoList
//
// Created by juanabreu on 2/15/14.
// Copyright (c) 2014 juanabreu. All rights reserved.
//
#import "JAMToDoList.h"
#import "JAMToDoItem.h"
@interface JAMToDoList ()
@property NSMutableArray *toDoItems;
//@property(nonatomic,strong) NSString *itemName;
@end
@implementation JAMToDoList
//@synthesize itemName;
-(IBAction)unwindToRootVC:(UIStoryboardSegue *)segue
{
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//instatiate the array;
self.toDoItems = [[NSMutableArray alloc]init];
[self LoadInitialData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)LoadInitialData{
JAMToDoItem *TheItem = [[JAMToDoItem alloc]init];
TheItem.itemName =@"Buy Milk";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
注意:LoadInitialData正在另一个类上实现,我试图实现JAMToDoItem属性的实例化。我基本上遵循APPLE所写的教程Here。在我的todolist类的顶部,我确实有#import "JAMToDoItem.h"
这是包含我试图设置的属性的类,以及我得到错误的地方。
所以错误我最终
Property 'itemName' not found on object of type 'JAMToDoItem *'
我错过了什么?
答案 0 :(得分:1)
UPD:
原因是还有其他JAMToDoItem.h
文件带有
//
// JAMToDoItem.h
// ToDoList
//
// Created by juanabreu on 2/15/14.
// Copyright (c) 2014 juanabreu. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface JAMToDoItem : UIViewController
@end
您可以通过Command +左键单击
找到它#import "JAMToDoItem.h"
它位于ToDoList/ToDoList/JAMToDoItem.h
,您展示的那个位于
ToDoList/JAMToDoItem.h
删除项目中对JAMToDoItem.h
和JAMToDoItem.m
的引用(选择并点击删除)
删除文件ToDoList/ToDoList/JAMToDoItem.h
和ToDoList/ToDoList/JAMToDoItem.m
将文件从ToDoList/JAMToDoItem.h
和ToDoList/JAMToDoItem.m
移至ToDoList/ToDoList/JAMToDoItem.h
和ToDoList/ToDoList/JAMToDoItem.m
选择它们并重新添加到项目中