ios - 更改自定义表格 View 单元格按钮的框架

标签 ios objective-c uitableview

在我的应用程序中,我在 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/

相关文章:

ios - uicollectionview单元格背景图像重复出现

ios - 如何修复 Alljoyn iOS SDK 构建失败并出现以下错误?

ios - UITextField 的奇怪行为和辞职的第一响应者

uitableview - popToRootViewControllerAnimated 没有更新 UITableView

ios - 当 iPad 上的 reloadData 从非零部分变为零部分时,UITableViewController 似乎不会刷新

ios - 枚举 NSString 的最佳方法

ios - 如何在 Swift 项目中添加微信 API?

objective-c - ios停止2个线程同时使用一个方法

ios - 除了模态视图 Controller 之外的所有 View Controller 中的纵向方向

ios - "Terminating app due to uncaught exception ' NSInvalidArgumentException '"