开发者

"Incompatible pointer..." warning on assigning delegate to self

I have a custom subclass of UITableView with a protocol defined in it as below:

#import <UIKit/UIKit.h>

@protocol CustomDelegate <NSObject>
@optional
-(NSInteger)numberOfRows;
@end

@interface CustomTV : UITableView <UITable开发者_开发技巧ViewDelegate, UITableViewDataSource>{  
    id<CustomDelegate> *del;
}
@property (nonatomic, assign)    id<CustomDelegate> *del;
@end

Now in some other class, I instantiate this CustomTV and set the delegate to self:

    CustomTV *tbl = [[CustomTV alloc] initWithFrame:CGRectMake(0, 0, 200, 400) style:UITableViewStylePlain];
    tbl.del = self;

Why do I get an "Incompatible pointer..." warning on the line tbl.del = self ?

I did conform to the CustomDelegate protocol in the header.


You are declaring the delegate as a pointer to a pointer to an object. The type id is already declared as a pointer to an object so remove the star.

@interface CustomTV : UITableView <UITableViewDelegate, UITableViewDataSource>{  
    id<CustomDelegate> del;
}
@property (nonatomic, assign)    id<CustomDelegate> del;
@end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜