2014-02-15 59 views
0

我有一個類似如下的類別。在物件類型上找不到物業

#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 *' 

錯誤我正在想什麼?

+0

請添加更多代碼。沒有對財產的訪問權限,錯誤是否出現? – gran33

+0

gran33我添加了正在撥打電話的完整課程,讓我知道您希望看到的其他代碼。沒有嘗試訪問該屬性,錯誤不會顯示。 – user677275

+3

請不要大寫方法和變量名稱。 – nhgrif

回答

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 

您可以通過命令+左鍵點擊

#import "JAMToDoItem.h" 

它位於ToDoList/ToDoList/JAMToDoItem.h找到它,您向我們展示的那個位於

ToDoList/JAMToDoItem.h 
  1. 在你的項目中刪除,以JAMToDoItem.hJAMToDoItem.m引用(選擇並點擊刪除)

  2. 刪除文件ToDoList/ToDoList/JAMToDoItem.hToDoList/JAMToDoItem.hToDoList/ToDoList/JAMToDoItem.m

  3. 移動文件和ToDoList/JAMToDoItem.mToDoList/ToDoList/JAMToDoItem.hToDoList/ToDoList/JAMToDoItem.m

  4. 選擇它們並重新添加到項目

+1

重新組織代碼的好的步驟。 – Pawan

+0

我覺得像這樣的驢子。謝謝你,當我在xcode中時,我簡單地將文件從一個目錄拖到另一個目錄,它必須創建一個複製凝灰石課程來學習。謝謝 ! – user677275