开发者

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

开发者 https://www.devze.com 2023-04-10 01:27 出处:网络
I have a custom subclass of UITableView with a protocol defined in it as below: #import <UIKit/UIKit.h>

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

精彩评论

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

关注公众号