【问题标题】:App crashing during AdHoc but not during debug应用程序在 AdHoc 期间崩溃,但在调试期间不崩溃
【发布时间】:2016-10-05 22:55:31
【问题描述】:

我的应用中有 1 个类在 AdHoc 部署期间崩溃,但如果通过 Xcode 安装则可以正常工作。我已经从我的设备(iOS 10)符号化了崩溃日志,它们都是一样的:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   UIKit                           0x0000000196507a4c __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 424
1   UIKit                           0x00000001965079f0 __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 332
2   UIKit                           0x00000001964c7368 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2712
3   UIKit                           0x00000001964c67e4 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 536
4   UIKit                           0x00000001964c6570 -[UITableViewRowData heightForTable] + 60

所以我的想法是,好吧,也许我如何找到我的部分计数存在问题。这是我的课程的代码,非常简单。

class HeaderTableViewController: UITableViewController {

    var nonDefaultTitle : String?
    
    var data: [String: [String]] = [:]
    
    var headers : [String]       = []
    var bodys   : [[String]]     = []
    
    
    init(displayData: [String: [String]]) {
        super.init(style: .Plain)
        data = displayData
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        for key in data.keys {
            headers.append(key)
        }
        
        for arr in data.values {
            bodys.append(arr)
        }
 
        tableView.registerNib(UINib(nibName: "DefaultCustomCell", bundle: nil), forCellReuseIdentifier: "DefaultCustomCell")
        tableView.estimatedRowHeight = 50
        tableView.rowHeight = UITableViewAutomaticDimension
        
        tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
        tableView.estimatedSectionHeaderHeight = 100;
        
        let nib = UINib(nibName: "HeaderTableHeaderView", bundle: nil)
        tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "HeaderTableHeaderView")
        
        if let ttle = nonDefaultTitle {
            self.title = ttle
        }
        else {
            self.title = "Talking Tips"
        }
    }
}

//
// MARK: Helpers
//
extension HeaderTableViewController {
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return headers.count
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return bodys[section].count
    }
    
    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let cell = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderTableHeaderView")
        let header = cell as? HeaderTableHeaderView
        header!.titleLabel.text = headers[section]

        return cell
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("DefaultCustomCell", forIndexPath: indexPath) as! DefaultCustomCell
        
        cell.titleLabel.text = bodys[indexPath.section][indexPath.row]
        cell.selectionStyle = .None
        return cell
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { }
}

//
// MARK: The table headers
//
class HeaderTableHeaderView: UITableViewHeaderFooterView {
    @IBOutlet weak var titleLabel: UILabel!
}

我的意思是它真的很简单。同样,如果我通过 xcode 安装,该应用程序可以正常工作。即使我安装,杀死应用程序,然后重新打开,一切正常。

每当我尝试通过 AdHoc(使用 Diawi)进行安装时,这个愚蠢的东西就会在这个类中崩溃。

【问题讨论】:

  • 奇怪的是:rectForFooterInSection,但你没有对页脚做任何事情。也许尝试将 sectionFooterHeight 设置为 0?

标签: ios swift uitableview crash


【解决方案1】:

我的问题最终变成了这个。设置这个:

tableView.sectionHeaderHeight = UITableViewAutomaticDimension;

viewDidLoad() 从 xcode 安装时不会导致崩溃。安装 OTA 后即可。通常我会复制我的“发布”构建设置,所以我认为可能有些不同。我创建了一个复制“调试”的新配置,并且发生了同样的崩溃。我不知道这是否是Apple方面的错误。

不管怎样,你不需要在viewDidLoad()中设置,你要做的就是拥有这个:

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return UITableViewAutomaticDimension
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多