应用程序在AdHoc期间崩溃但在调试期间不会崩溃

时间:2016-10-05 22:55:31

标签: ios swift uitableview crash

我的应用中有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)时,这个类中的愚蠢事情都会崩溃。

1 个答案:

答案 0 :(得分:0)

我的问题最终成了这样。设置此:

tableView.sectionHeaderHeight = UITableViewAutomaticDimension;

从xcode安装时,viewDidLoad()中不会导致崩溃。安装OTA时会。通常我复制我的“发布”构建设置,所以我想也许有些不同的东西。我创建了一个重复“Debug”的新配置,同样的崩溃发生了。我不知道这是否是Apple方面的错误。

无论如何,您不需要设置viewDidLoad(),您需要做的就是:

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