首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我的NSException打开时,app正在“NSException类型的异常终止”

当我的NSException打开时,app正在“NSException类型的异常终止”
EN

Stack Overflow用户
提问于 2017-02-08 07:10:11
回答 1查看 220关注 0票数 0

我的应用程序,我一直在处理崩溃后,ViewDidAppears功能。我的错误:

代码语言:javascript
复制
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.6.22/UITableView.m:8042
2017-02-08 01:58:53.747017 APP_Name[841:223668] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x1018d4000; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x174056d70>; layer = <CALayer: 0x174037200>; contentOffset: {0, 0}; contentSize: {375, 200}>) failed to obtain a cell from its dataSource (<App_Name.FindAParrty: 0x101242370>)'
*** First throw call stack:
(0x18d1611b8 0x18bb9855c 0x18d16108c 0x18dc1902c 0x193157d3c 0x193359bc4 0x193359d88 0x193347320 0x19335edec 0x1930fade8 0x193013a80 0x1904c19d8 0x1904b64cc 0x1904b638c 0x1904333e0 0x19045aa68 0x19045b488 0x18d10e0c0 0x18d10bcf0 0x18d10c180 0x18d03a2b8 0x18eaee198 0x1930817fc 0x19307c534 0x1000c5e58 0x18c01d5b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

在做了研究之后,我读到一个可能的错误是,我没有命名一个重用标识符,但是我这样做了,之后我就不知所措了。我不知道我是不是错过了什么或者是什么交易。

下面是参考文献的TableView:

代码语言:javascript
复制
class FindAParty:UITableViewController{

    var partyData:NSMutableArray! = NSMutableArray()
    //var user:NSMutableArray = NSMutableArray()

    override init(style: UITableViewStyle){
        super.init(style: style)

    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        //fatalError("init(coder:) has not been implemented")

    }


    @IBAction func loadData(){
        print ("Load Data went through")
        partyData.removeAllObjects()
        print ("Remove ALL Objeccts")
        let findPartyData:PFQuery = PFQuery(className: "Party")
        print("PFQuery...")
        findPartyData.findObjectsInBackground{
            (objects:[PFObject]?, error:Error?)->Void in

            if error != nil {

                print("Error")


            }else{

                for object in objects!{

                    let party:PFObject = object as PFObject
                    self.partyData.add("party")
                    }

                let array:NSArray = self.partyData.reverseObjectEnumerator().allObjects as NSArray
                self.partyData = NSMutableArray(array: array)

                self.tableView.reloadData()

            }
        }
    }

    override func viewDidAppear(_ animated: Bool) {
        self.loadData()
        print("View Did Appear")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        print("ViewDidLoad")
        //self.loadData()
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem
    }

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

    // #pragma mark - Table view data source

    func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }

    override func tableView(_ tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return partyData.count
    }


    func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
        let cell:FindAPartyCell = tableView!.dequeueReusableCell(withIdentifier: "Cell", for: indexPath! as IndexPath) as! FindAPartyCell

        let party:PFObject = self.partyData.object(at: indexPath!.row) as! PFObject

        cell.typeOfPartyLabel.alpha = 0
        cell.timeOfPartyLabel.alpha = 0
        cell.usernameLabel.alpha = 0

        cell.typeOfPartyLabel.text = party.object(forKey: "partyTitle") as? String
        cell.timeOfPartyLabel.text = party.object(forKey: "partyTime") as? String
        cell.usernameLabel.text = party.object(forKey: "Username") as? String

       // var dataFormatter:NSDateFormatter = NSDateFormatter()
        //dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
        //cell.timestampLabel.text = dataFormatter.stringFromDate(sweet.createdAt)

        let findUser:PFQuery = PFUser.query()!
        findUser.whereKey("objectId", equalTo: party.object(forKey: "Username")!)



        findUser.findObjectsInBackground {
            (objects:[PFObject]?, error: Error?) -> Void in // Changes NSError to Error
            if error == nil{

                let user:PFUser = (objects)!.last as! PFUser
                cell.usernameLabel.text = user.username

                UIView.animate(withDuration: 0.5, animations: {
                    cell.typeOfPartyLabel.alpha = 1
                    cell.timeOfPartyLabel.alpha = 1
                    cell.usernameLabel.alpha = 1
                })
            }
        }


        return cell
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-08 07:20:21

  1. 您正在使用表视图的旧委托方法,请使用以下方法: func numberOfSections( tableView: UITableView) -> Int {返回xxx } func tableView(_ tableView: UITableView,numberOfRowsInSection节: Int) -> Int { cell xxx } func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath)FindAPartyCell返回单元}
  2. 您确定您的原型Cell标识符是在IB中用FindAPartyCell分配的吗?
  3. 尽量不要在findUser.findObjectsInBackground方法中执行cellForRowAt操作。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42106819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档