0

在 fastpdfkit 中有这样的委托声明

@interface BookmarkViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

//Delegate to get the current page and tell to show a certain page. It can also be used to
//  get a list of bookmarks for the current document. 

NSObject<BookmarkViewControllerDelegate> *delegate; 
 }

@property (nonatomic, assign) NSObject<BookmarkViewControllerDelegate> *delegate;

@synthesize delegate;

由于我使用 ARC,所以委托的声明是这样的

@interface BookmarkViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

 id __unsafe_unretained <BookmarkViewControllerDelegate> delegate;
 }

@property (unsafe_unretained) id <BookmarkViewControllerDelegate> delegate;

 @synthesize delegate;

当我调试我得到时,它是正确的原因吗

 currentPage    NSUInteger  0
delegate    objc_object *   0x00000000
4

1 回答 1

5

这是一个要遵循的模式。委托被正确声明为弱(一个对象但没有所有权转移或保留计数增加)。

@protocol MyClassDelegate;

@interface MyClass : NSObject

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

@end

@protocol MyClassDelegate <NSObject>

- (void)myClass:(MyClass *)myClass didSomethingAtTime:(NSDate *)time;
- (CGSize)sizeofSomethingNeededByMyClass:(MyClass *)myClass;

// and so on

@end
于 2013-08-17T22:16:27.517 回答