我有一個類似如下的類別。在物件類型上找不到物業
#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
然後我嘗試訪問propertys在這個類像下面和IM得到一個錯誤
//
// 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 [email protected]"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"
這是包含propertys im試圖設置的類,以及即時獲取錯誤的地方。
所以我最終
Property 'itemName' not found on object of type 'JAMToDoItem *'
錯誤我正在想什麼?
請添加更多代碼。沒有對財產的訪問權限,錯誤是否出現? – gran33
gran33我添加了正在撥打電話的完整課程,讓我知道您希望看到的其他代碼。沒有嘗試訪問該屬性,錯誤不會顯示。 – user677275
請不要大寫方法和變量名稱。 – nhgrif