2011-10-03 59 views
1

分配委託警告我的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; 

爲什麼我會得到一個「不兼容的指針......」就行了tbl.del = self警告?

我確實符合標題中的CustomDelegate協議。

回答

3

您正在將委託聲明爲指向指向對象的指針。 id類型已經被聲明爲一個指向對象的指針,所以刪除星號。

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

哦,謝謝你!簡直不敢相信我是怎麼錯過的 – NSExplorer