实现文件无法查看协议委托

时间:2014-07-21 21:07:43

标签: ios objective-c xcode

已在头文件中声明了一个协议,但实现文件说它无法看到该委托。为什么呢?

Xcode编译器消息在实现文件中被注释掉。

提前致谢。

AddItemViewController.h

#import <UIKit/UIKit.h>

@class AddItemViewController;
@class ChecklistItem;

@protocol AddItemViewControllerDelegate <NSObject>

- (void)addItemViewControllerDidCancel:(AddItemViewController *)controller;
- (void)addItemViewController:(AddItemViewController *)controller didFinishAddingItem:(ChecklistItem *)item;

@property (nonatomic, weak) id <AddItemViewControllerDelegate> delegate;

@end

@interface AddItemViewController : UITableViewController <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneBarButton;

- (IBAction)cancel;
- (IBAction)done;

@end

AddItemViewController.m

- (IBAction)cancel
{
    [self.delegate addItemViewControllerDidCancel:self]; /* Semantic issue: Property 'delegate' not found on object of  type     "AddItemViewController" */
}

- (IBAction)done
{
    ChecklistItem *item = [[ChecklistItem alloc] init];
    item.text = self.textField.text;
    item.checked = NO;

    [self.delegate AddItemViewController:self didFinishAddingItem:item]; /* Semantic issue: Property 'delegate' not found on object of  type     "AddItemViewController" */

}

1 个答案:

答案 0 :(得分:3)

这是一个错字吗?委托属性是在委托协议上定义的。当然VC类看不到它;)