[英]Method not working - customize cell
我有自定義的UITableViewCell
類,在其中編寫了一種方法來正確初始化單元格的內容和外觀。 現在我希望單元格為圓形並帶有邊框。 首先,我寫道:
-(void)cornerCell:(UITableViewCell*)cell withImageView:(UIImageView*)imageView{
cell.imageView.layer.cornerRadius = 33;
cell.imageView.clipsToBounds = YES;
cell.separatorInset = UIEdgeInsetsMake(0, 82, 0, 0);
cell.imageView.layer.borderWidth = 5.0;
}
然后,在我的方法(用於填充單元格內容)中,我寫了以下內容:
Declared in myCell.m
-(void)fillCellWithTableViewIndex:(NSInteger)index withTableView:(UITableView*)myTableView withImageView:(UIImageView*)imageView{
...some code
[self cornerCell:self withImageView:self.myCellImageView];
之后,我在ViewController
調用cellForRowAtIndexPath
方法:
在viewController.m中聲明
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...some code
[cell fillCellWithTableViewIndex:indexPath.row withTableView:tableView withImageView:cell.myCellImageView];
return cell;
}
它不起作用。 但是,當我打電話時
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...some code
[cell fillCellWithTableViewIndex:indexPath.row withTableView:tableView withImageView:cell.myCellImageView];
cell.myCellImageView.layer.cornerRadius = 33;
cell.myCellImageView.clipsToBounds = YES;
cell.separatorInset = UIEdgeInsetsMake(0, 82, 0, 0);
cell.myCellImageView.layer.borderWidth = 5.0;
return cell;
}
它的工作,但看起來很丑陋,並且與簡潔明了的代碼的一般概念背道而馳。 為什么我的第一次嘗試無效?
我希望我能清楚地描述所有問題,請嘗試找出問題所在。
在你的方法,你不使用傳入imageView
,您使用的電池的內置cell.imageView
,這顯然是不一樣的。
-(void)cornerCell:(UITableViewCell*)cell withImageView:(UIImageView*)imageView{
cell.imageView.layer.cornerRadius = 33;
cell.imageView.clipsToBounds = YES;
cell.separatorInset = UIEdgeInsetsMake(0, 82, 0, 0);
cell.imageView.layer.borderWidth = 5.0;
}
您為什么根本不使用imageView
參數?
cell.imageView
意味着您使用通用的.imageView
屬性,但似乎您想要cell.myCellImageView
您的自定義屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.