2 sachinks SachinKS 于 2013.08.19 17:20 提问

使用ARC声明delegates

在fastpdfkit中声明delegates:

@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

1个回答

loFataMer
loFataMer   2013.08.19 17:29
已采纳

这有一个模式,delegates声明为weak。

@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
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!