“不兼容的指针...”警告将委托分配给自己

时间:2011-10-03 16:57:54

标签: objective-c ios uitableview delegates

我有一个UITableView的自定义子类,其中定义了一个协议,如下所示:

#import <UIKit/UIKit.h>

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

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

现在在其他一些课程中,我实例化了这个CustomTV并将委托设置为self:

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

为什么我会得到一个&#34;不兼容的指针......&#34;警告线tbl.del = self

我确实符合标题中的CustomDelegate协议。

1 个答案:

答案 0 :(得分:3)

您将委托声明为指向对象指针的指针。类型id已被声明为指向对象的指针,因此请删除星号。

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