在我的应用程序中,我在 UITableView 中显示待售商品列表。如果用户没有对某个项目设置描述,我想调整单元格中某些元素的位置以适应空白标签。
我的 cellForRowAtIndexPath
中的以下代码无法正常工作。
cell.productName.text = product.fields[@"title"];
cell.productPrice.text = product.fields[@"price"];
cell.productDescription.text = vehicle.fields[@"salespersonComments"];
if ([cell.productDescription.text isEqualToString:@""]) {
CGRect f = cell.favoriteButton.frame;
f.origin.y = 10; // new y
cell.favoriteButton.frame = f;
} else {
}
最佳答案
//You have to use the UITableView delegate methods
//Method for displaying the cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
}
}
//Method for adjusting the cell height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
关于ios - 更改自定义表格 View 单元格按钮的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33067999/