崩溃的应用程序,当iOS尝试将单词移到其他行时(如果不合适)

时间:2018-10-05 09:23:41

标签: ios swift uilabel

在我的工作中,我必须重新设计旧的应用程序。 因此,我将其重构为Omg,当我向Label发送特定文本时,应用程序崩溃了。

我正在寻找它(示例),当我发送给Label文本“ Blablabl b blablabl”,并将Label行数设置为0(Label具有帧100x100)时,应用崩溃了,但是如果我将numberoflines设置为1,应用不会崩溃,不会截断像“ Blablabl b ...”这样的文本的尾巴。

换句话说,当iOS尝试将单词移至其他行时,应用程序崩溃。 所以我有几个问题。为什么应用崩溃了。我该如何解决。

如果我发送给Label“ Blablablablalbalblablabllabl”并将numberOfLines设置为0,则表示确定,并且Label看起来像:

lablablablal

balblablablla

bl

override func viewWillAppear(_ animated: Bool) {

    let tile = TileView()
    let grt = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
    tile.frame = grt
    let tit = UILabel(frame: grt)
    tit.text = "Blablablablalbalblablabllabl"
    let but = UIButton(frame: grt)
    let ov = UIView(frame: grt)
    let im = UIImageView(frame: grt)
    let arr = [im, ov, tit, but]
    for i in arr {
        tile.addSubview(i)
    }
    tile.tileButton = but
    tile.tileTitle = tit
    tile.tileTitle.numberOfLines = 0
    tile.tileOverlay = ov
    tile.tileOverlay.backgroundColor = .black
    tile.tileOverlay.alpha = 0.5
    tile.tileImage = im
    view.insertSubview(tile, aboveSubview: collectionView)
}

TileView.swift

import UIKit
import Foundation

protocol TileDelegate: class {
    func tapOnTile(with item: AppDesign.Screens.Main.ButtonItem)
}

class TileView: UIView {

    @IBOutlet weak var tileImage: UIImageView!
    @IBOutlet weak var tileOverlay: UIView!

    @IBOutlet weak var tileTitle: UILabel!

    @IBOutlet weak var tileButton: UIButton!

    weak var delegate: TileDelegate?

    fileprivate var block: AppDesign.Screens.Main.ButtonItem!

    @objc fileprivate func clickOnButton(_ sender: UIButton) {
        delegate?.tapOnTile(with: block)
    }

    public func fillTile(with item: AppDesign.Screens.Main.ButtonItem) {
        block = item

        tileTitle.text = item.title

        tileOverlay.backgroundColor = item.blackout.withAlphaComponent(0.5)

        if let imageUrl = URL(string: item.image) {
            tileImage.af_setImage(withURL: imageUrl)
        }

        tileTitle.textColor = item.textColor
        layer.cornerRadius = 10
        clipsToBounds = true

        tileButton.addTarget(self, action: #selector(clickOnButton(_:)), for: .touchUpInside)

    }

}

首先,应用程序因日志崩溃:

2018-10-01 16:25:48.132636+0300 iosProj[20881:378165] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.

2018-10-01 16:25:53.125100+0300 iosProj[20881:378165] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
libc++abi.dylib: terminating with uncaught exception of type NSException

所以现在就: libc ++ abi.dylib:以类型为NSException的未捕获异常终止

0 个答案:

没有答案