我有一個自定義的UITableViewCell,我要覆蓋像下面的init方法:重寫自定義單元格initWithStyle方法,但它沒有被稱爲
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
self.buttons = [[NSMutableArray alloc] initWithObjects:self.button1, self.button2,self.button3,self.button4, nil];
self.labels = [[NSMutableArray alloc] initWithObjects:self.label1,self.label2,self.label3,self.label4, nil];
NSLog(@"init done");
return self;
}
我需要這個方法把我的按鈕和標籤在數組中。我使用下面的代碼創建單元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FriendViewCell *cell = (FriendViewCell *)[tableView dequeueReusableCellWithIdentifier:@"friendCell" forIndexPath:indexPath];
}
但是,init方法未被調用且數組爲零。不知道發生了什麼!我是否覆蓋了正確的方法?
我需要保持訂購按鈕,有沒有辦法從故事板調用自定義的init方法呢? – Kex 2015-02-11 09:35:23
@Kex不是'init'方法。使用'awakeFromNib'。 – Sulthan 2015-02-11 09:48:41
謝謝你,現在正在工作 – Kex 2015-02-11 10:13:47