我的应用程序,我一直在处理崩溃后,ViewDidAppears功能。我的错误:
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:
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
}
}发布于 2017-02-08 07:20:21
Cell标识符是在IB中用FindAPartyCell分配的吗?findUser.findObjectsInBackground方法中执行cellForRowAt操作。https://stackoverflow.com/questions/42106819
复制相似问题