簡體   English   中英

靜態 UITableView 中的自定義 UITableViewCell

[英]Custom UITableViewCell in static UITableView

我已經定義了一個自定義UITableViewCell ,我在我的靜態UITableView 我想訪問我定義的變量( myTableViewImageCell等),但這樣做tableView:willDisplayCell似乎是說一起的“細胞類型的重新定義線的東西。

這是我在做什么:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];   


}

如果您的所有單元格都是同一個自定義類,您只需更改方法的定義以表明這一點並刪除您的第一行(無論如何這是錯誤的):

- (void)tableView:(UITableView *)tableView willDisplayCell:(ANMyTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];
    [cell.myTableViewLabel setTextColor:[UIColor hex666Color]];      
}

但是請注意,如果您對所有單元格執行相同的操作(如您在此處顯示的那樣),您應該在cellForRowAtIndexPath:而不是willDisplayCell:執行此willDisplayCell: 這樣,代碼僅在創建單元格時運行一次,而不是每次顯示時運行。

僅供參考,問題是無關的;細胞; 你在第二行的末尾。 將其更改為

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    ANMyTableViewCell *cell = (ANMyTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];
    [cell.myTableViewLabel setTextColor:[UIColor hex666Color]];      
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM