Swift "Specialized" 崩溃
Swift "Specialized" Crash
下面是我的一个应用程序中不断发生的崩溃的堆栈跟踪。我不知道如何解决它并且它并不总是发生?请帮助:)
它与 Swift 泛型有关吗?
Thread : Crashed: com.apple.main-thread
0 MyApp 0x1000f4f5c specialized FriendsTableViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (FriendsTableViewController.swift)
1 MyApp 0x1000f1f60 @objc FriendsTableViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (FriendsTableViewController.swift)
2 UIKit 0x1867ad31c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 692
3 UIKit 0x1867ad484 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
4 UIKit 0x18679c9b8 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2824
5 UIKit 0x186539208 -[UITableView _setNeedsVisibleCellsUpdate:withFrames:] + 240
6 UIKit 0x1865390d0 -[UITableView _rectChangedWithNewSize:oldSize:] + 996
7 UIKit 0x186546df4 -[UITableView setBounds:] + 256
8 UIKit 0x18647a2bc -[UIScrollView setContentOffset:] + 424
9 UIKit 0x1865382bc -[UITableView setContentOffset:] + 300
10 UIKit 0x186780a3c -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 60
11 UIKit 0x18677ab5c -[UIScrollView _updateForChangedScrollRelatedInsets] + 48
12 UIKit 0x18651d5ac -[UIScrollView setContentInset:] + 116
13 UIKit 0x186546c50 -[UITableView setContentInset:] + 132
14 UIKit 0x1865bf250 -[UIScrollView(UIScrollViewInternal) _adjustForAutomaticKeyboardInfo:animated:lastAdjustment:] + 348
15 UIKit 0x1865bf0b8 -[UITableView _adjustForAutomaticKeyboardInfo:animated:lastAdjustment:] + 108
16 UIKit 0x186d50380 -[UIAutoRespondingScrollViewControllerKeyboardSupport _adjustScrollViewForKeyboardInfo:] + 288
17 Foundation 0x18211e44c __NSFireDelayedPerform + 428
18 CoreFoundation 0x1817215f4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
19 CoreFoundation 0x181721298 __CFRunLoopDoTimer + 884
20 CoreFoundation 0x18171e9ac __CFRunLoopRun + 1520
21 CoreFoundation 0x18164d680 CFRunLoopRunSpecific + 384
22 GraphicsServices 0x182b5c088 GSEventRunModal + 180
23 UIKit 0x1864c4d90 UIApplicationMain + 204
24 MyApp 0x100094ef8 main (AppDelegate.swift:15)
25 libdispatch.dylib 0x1811ee8b8 (Missing
除此之外,这是我拥有的 cellForRow 函数
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section < 2 {
let cell = tableView.dequeueReusableCellWithIdentifier("FriendCell", forIndexPath: indexPath) as! FriendTableViewCell
cell.tag = indexPath.row
var user: TetherUser!
if searching {
user = searchedUsers[indexPath.row]
} else {
if indexPath.section == 0 {
user = users[indexPath.row]
cell.actionButton.friendIsContact = false
} else if indexPath.section == 1 {
user = contactsWithApp[indexPath.row]
cell.actionButton.friendIsContact = true
}
}
user.tag = indexPath.row
cell.nameLabel.text = user.fullName
cell.profileImageView.image = nil
user.profileImage { (image) -> Void in
if user.tag == cell.tag {
cell.profileImageView.image = image
}
}
if let currentUserID = TetherManager.sharedInstance.currentTetherUser?.objectId {
cell.actionButton.type = user.relationToUserWithID(currentUserID)
cell.actionButton.tag = indexPath.row
cell.actionButton.delegate = self
switch user.relationToUserWithID(currentUserID) {
case .None:
cell.actionButton.button.setImage(UIImage(named: "AddFriend"), forState: .Normal)
break
case .SentFriendRequest:
cell.actionButton.button.setImage(UIImage(named: "ReceivedFriendRequest"), forState: .Normal)
break
case .ReceivedFriendRequest:
cell.actionButton.button.setImage(UIImage(named: "PendingFriendRequest"), forState: .Normal)
break
case .Friends:
cell.actionButton.button.setImage(UIImage(named: "RemoveFriend"), forState: .Normal)
break
}
}
return cell
} else {
//Contacts
let cell = tableView.dequeueReusableCellWithIdentifier("ContactCell", forIndexPath: indexPath) as! ContactTableViewCell
cell.contact = addressBookContacts[indexPath.row]
cell.delegate = self
return cell
}
}
您需要为 indexPath.section == 2 的情况创建用户对象,因为您有 3 个部分。您将需要确保 'user' 对象在此代码块中正确初始化(请参阅代码中的内联注释)
var user: TetherUser!
if searching {
user = searchedUsers[indexPath.row]
} else {
if indexPath.section == 0 {
user = users[indexPath.row]
cell.actionButton.friendIsContact = false
} else if indexPath.section == 1 {
user = contactsWithApp[indexPath.row]
cell.actionButton.friendIsContact = true
} else if indexPath.section == 2 {
// Add code here to ensure user has proper value.
}
}
我也有这个 "specialized" 错误。崩溃仅发生在 iOS 8.0 和 8.1 上。这是我的堆栈跟踪的一部分。
Crashed: com.apple.main-thread
0 Viki 0x10027bb28 specialized LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () + 4297243432
1 Viki 0x10027ad30 @objc LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () (LoginFlowButton.swift)
2 UIKit 0x18a696cd4 -[UIView _processTraitsDidChangeRecursively:forceNotification:] + 124
3 UIKit 0x18a3d05f4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 348
4 UIKit 0x18a3d0408 -[UIView(Hierarchy) _postMovedFromSuperview:] + 484
5 UIKit 0x18a3dbea4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1724
6 UIKit 0x18a694f34 -[UIView initWithCoder:] + 756
...
我尝试下载一个 iOS 具有这些版本的模拟器并再次测试。原来崩溃是由于使用强制展开的 var 但在 traitCollectionDidChange
函数中发现 nil
。
所以这里的教训只是错误信息中的specialized
函数可能没有指向确切的问题。您可以尝试更多地研究该函数,看看那里出了什么问题。
希望对您有所帮助。 :)
下面是我的一个应用程序中不断发生的崩溃的堆栈跟踪。我不知道如何解决它并且它并不总是发生?请帮助:)
它与 Swift 泛型有关吗?
Thread : Crashed: com.apple.main-thread
0 MyApp 0x1000f4f5c specialized FriendsTableViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (FriendsTableViewController.swift)
1 MyApp 0x1000f1f60 @objc FriendsTableViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (FriendsTableViewController.swift)
2 UIKit 0x1867ad31c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 692
3 UIKit 0x1867ad484 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
4 UIKit 0x18679c9b8 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2824
5 UIKit 0x186539208 -[UITableView _setNeedsVisibleCellsUpdate:withFrames:] + 240
6 UIKit 0x1865390d0 -[UITableView _rectChangedWithNewSize:oldSize:] + 996
7 UIKit 0x186546df4 -[UITableView setBounds:] + 256
8 UIKit 0x18647a2bc -[UIScrollView setContentOffset:] + 424
9 UIKit 0x1865382bc -[UITableView setContentOffset:] + 300
10 UIKit 0x186780a3c -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 60
11 UIKit 0x18677ab5c -[UIScrollView _updateForChangedScrollRelatedInsets] + 48
12 UIKit 0x18651d5ac -[UIScrollView setContentInset:] + 116
13 UIKit 0x186546c50 -[UITableView setContentInset:] + 132
14 UIKit 0x1865bf250 -[UIScrollView(UIScrollViewInternal) _adjustForAutomaticKeyboardInfo:animated:lastAdjustment:] + 348
15 UIKit 0x1865bf0b8 -[UITableView _adjustForAutomaticKeyboardInfo:animated:lastAdjustment:] + 108
16 UIKit 0x186d50380 -[UIAutoRespondingScrollViewControllerKeyboardSupport _adjustScrollViewForKeyboardInfo:] + 288
17 Foundation 0x18211e44c __NSFireDelayedPerform + 428
18 CoreFoundation 0x1817215f4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
19 CoreFoundation 0x181721298 __CFRunLoopDoTimer + 884
20 CoreFoundation 0x18171e9ac __CFRunLoopRun + 1520
21 CoreFoundation 0x18164d680 CFRunLoopRunSpecific + 384
22 GraphicsServices 0x182b5c088 GSEventRunModal + 180
23 UIKit 0x1864c4d90 UIApplicationMain + 204
24 MyApp 0x100094ef8 main (AppDelegate.swift:15)
25 libdispatch.dylib 0x1811ee8b8 (Missing
除此之外,这是我拥有的 cellForRow 函数
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section < 2 {
let cell = tableView.dequeueReusableCellWithIdentifier("FriendCell", forIndexPath: indexPath) as! FriendTableViewCell
cell.tag = indexPath.row
var user: TetherUser!
if searching {
user = searchedUsers[indexPath.row]
} else {
if indexPath.section == 0 {
user = users[indexPath.row]
cell.actionButton.friendIsContact = false
} else if indexPath.section == 1 {
user = contactsWithApp[indexPath.row]
cell.actionButton.friendIsContact = true
}
}
user.tag = indexPath.row
cell.nameLabel.text = user.fullName
cell.profileImageView.image = nil
user.profileImage { (image) -> Void in
if user.tag == cell.tag {
cell.profileImageView.image = image
}
}
if let currentUserID = TetherManager.sharedInstance.currentTetherUser?.objectId {
cell.actionButton.type = user.relationToUserWithID(currentUserID)
cell.actionButton.tag = indexPath.row
cell.actionButton.delegate = self
switch user.relationToUserWithID(currentUserID) {
case .None:
cell.actionButton.button.setImage(UIImage(named: "AddFriend"), forState: .Normal)
break
case .SentFriendRequest:
cell.actionButton.button.setImage(UIImage(named: "ReceivedFriendRequest"), forState: .Normal)
break
case .ReceivedFriendRequest:
cell.actionButton.button.setImage(UIImage(named: "PendingFriendRequest"), forState: .Normal)
break
case .Friends:
cell.actionButton.button.setImage(UIImage(named: "RemoveFriend"), forState: .Normal)
break
}
}
return cell
} else {
//Contacts
let cell = tableView.dequeueReusableCellWithIdentifier("ContactCell", forIndexPath: indexPath) as! ContactTableViewCell
cell.contact = addressBookContacts[indexPath.row]
cell.delegate = self
return cell
}
}
您需要为 indexPath.section == 2 的情况创建用户对象,因为您有 3 个部分。您将需要确保 'user' 对象在此代码块中正确初始化(请参阅代码中的内联注释)
var user: TetherUser!
if searching {
user = searchedUsers[indexPath.row]
} else {
if indexPath.section == 0 {
user = users[indexPath.row]
cell.actionButton.friendIsContact = false
} else if indexPath.section == 1 {
user = contactsWithApp[indexPath.row]
cell.actionButton.friendIsContact = true
} else if indexPath.section == 2 {
// Add code here to ensure user has proper value.
}
}
我也有这个 "specialized" 错误。崩溃仅发生在 iOS 8.0 和 8.1 上。这是我的堆栈跟踪的一部分。
Crashed: com.apple.main-thread
0 Viki 0x10027bb28 specialized LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () + 4297243432
1 Viki 0x10027ad30 @objc LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () (LoginFlowButton.swift)
2 UIKit 0x18a696cd4 -[UIView _processTraitsDidChangeRecursively:forceNotification:] + 124
3 UIKit 0x18a3d05f4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 348
4 UIKit 0x18a3d0408 -[UIView(Hierarchy) _postMovedFromSuperview:] + 484
5 UIKit 0x18a3dbea4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1724
6 UIKit 0x18a694f34 -[UIView initWithCoder:] + 756
...
我尝试下载一个 iOS 具有这些版本的模拟器并再次测试。原来崩溃是由于使用强制展开的 var 但在 traitCollectionDidChange
函数中发现 nil
。
所以这里的教训只是错误信息中的specialized
函数可能没有指向确切的问题。您可以尝试更多地研究该函数,看看那里出了什么问题。
希望对您有所帮助。 :)