Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 仅设置一个静态UITableViewCell的高度_Swift_Uitableview - Fatal编程技术网

Swift 仅设置一个静态UITableViewCell的高度

Swift 仅设置一个静态UITableViewCell的高度,swift,uitableview,Swift,Uitableview,我试图在Swift中设置静态UITableViewCell IBOutlet的高度。这可能吗?我已经找到了如何更改tableview中所有单元格的答案,但我只想更改这个单元格,并保持其余单元格在IB中的大小不变 我试过这个: override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { if indexPath.section

我试图在Swift中设置静态UITableViewCell IBOutlet的高度。这可能吗?我已经找到了如何更改tableview中所有单元格的答案,但我只想更改这个单元格,并保持其余单元格在IB中的大小不变

我试过这个:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.section == 1 && indexPath.row == 1 {
        return CGFloat(screenSize.width)
    }
    else{   
        return UITableViewAutomaticDimension
    }
}

要在静态TableViewCell上动态设置高度,实际上必须在
heightforrowatinexpath
中设置它。下面是一个更改第一部分中第二行的实现:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    if indexPath.section == 0 && indexPath.row == 1 {
        // Here return a number for the height you desire
        return CGFloat(100)
    }
    else {
        return UITableViewAutomaticDimension
    }
}
以下是一些可能与您的情况相关的提示。如果它们是在代码中故意做的,请忽略它们


单元格的高度设置为屏幕的宽度,可能值得检查这是否是有意的。另外,请记住,节和行都从索引0开始,而不是从索引1开始。

这不起作用,因为return UITableViewAutomaticDimension将每隔一行的默认大小设置为42(或任意大小)即使它们有其他大小是否每个都有不同的大小?是的,它们是@Tokuriku,那么您可以在
if,else if,else
格式中检查每个
indexPath.row
,并为它们分配正确的高度:)