小编Jac*_*ace的帖子

如何使用Swift创建具有动态单元格高度的静态单元格

我已经看了几个教程,展示了如何设置动态单元格高度,但是如果你通过设置适当的约束和使用动态单元格,它们都只显示它UITableViewAutomaticDimension.但是,我想对静态细胞这样做.

我的应用程序中有一个表视图控制器,其中包含几个单元格,这些单元格显示带有公开指示符的类别,其中有标题,然后是描述,描述文本的大小各不相同.因此,我希望单元格的高度根据描述文本的大小是动态的.

我使用静态单元而不是动态单元的原因是因为在类别单元格之上我有一些具有一些设计的单元格,我只能通过使用静态单元格和故事板来获得.

我正在使用iOS9,Xcode 7.3Swift 2.2

UPDATE

表视图控制器代码

import UIKit

class CategoriesTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 140
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: …
Run Code Online (Sandbox Code Playgroud)

ios swift xcode7.3

8
推荐指数
2
解决办法
6055
查看次数

以编程方式使用自动布局约束将UIImageView置于UIView Swift 2.3 iOS10内部

我已通过我的情节提要向表单元格添加了一个UIView,并具有以下约束:

在此处输入图片说明

然后,我得到以下代码,以编程方式将UIImageView添加到上述UIView并根据屏幕方向调整其大小。

            //Use half the screen size width when on an iPhone and on Landscape
            let image: UIImage = UIImage(named: HEADER_IMAGE_BATH)!
            imageView = UIImageView(image: image)
            imageView!.frame = CGRectMake(0 , 0, self.view.frame.width / 2, 185)
            imageView!.contentMode = .ScaleAspectFit
            //center image
            let centerXConst = NSLayoutConstraint(item: imageView!, attribute: .CenterX, relatedBy: .Equal, toItem: imageWrapperView, attribute: .CenterX, multiplier: 1, constant: 1)
            let centerYConst = NSLayoutConstraint(item: imageView!, attribute: .CenterY, relatedBy: .Equal, toItem: imageWrapperView, attribute: .CenterY, multiplier: 1, constant: 1)
            NSLayoutConstraint.activateConstraints([centerXConst, centerYConst])
            //add to sub view
            imageWrapperView.addSubview(imageView!) …
Run Code Online (Sandbox Code Playgroud)

ios autolayout swift

2
推荐指数
1
解决办法
2547
查看次数

在Swift 2.2中呈现弹出窗口时,在关闭错误中隐式使用'self'

如果用户成功重置密码,我试图将视图控制器显示为弹出窗口。基本上,如果通过电子邮件发送密码重置说明电子邮件都可以,则将运行以下代码。但是,我得到了错误

隐式使用“自我”封闭用户;使用“ .self”使捕获语义明确

在下面的第一行:

    let VC = storyboard?.instantiateViewControllerWithIdentifier("ResetPasswordSuccessPopOver") as! ResetPasswordSuccessPopOverViewController
    VC.preferredContentSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: 100)
    let navController = UINavigationController(rootViewController: VC)
    navController.modalPresentationStyle = UIModalPresentationStyle.Popover
    let popover = navController.popoverPresentationController
    popover?.delegate = self

   self.presentViewController(navController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

ios swift

1
推荐指数
1
解决办法
7596
查看次数

标签 统计

ios ×3

swift ×3

autolayout ×1

xcode7.3 ×1