选择 table 单元格以显示 iOS7 和 "unrecognized selector sent to instance" 上的新视图崩溃
Selecting table cell to show new view crashes on iOS7 with "unrecognized selector sent to instance"
我是 iOS 开发的新手,我在 Swift 中编写了一个 RSS 提要 reader。提要项显示在 UITableView 中。当我 select(触摸、单击)一个项目时,会显示一个新的 UIView,显示 selected 项目的提要描述。
它适用于 iOS8,但是当我尝试 iOS7 时,应用程序崩溃并且我得到以下输出:
2015-03-06 21:18:50.009 FeedReaderApp[9084:607] -[FeedReaderApp.TableViewController showViewController:sender:]: unrecognized selector sent to instance 0x7be8b100
2015-03-06 21:18:50.012 FeedReaderApp[9084:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FeedReaderApp.TableViewController showViewController:sender:]: unrecognized selector sent to instance 0x7be8b100'
*** First throw call stack:
(
0 CoreFoundation 0x006a61e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01c4d8e5 objc_exception_throw + 44
2 CoreFoundation 0x00743243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0069650b ___forwarding___ + 1019
4 CoreFoundation 0x006960ee _CF_forwarding_prep_0 + 14
5 FeedReaderApp 0x000b8068 _TFC12FeedReaderApp19TableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 1400
6 FeedReaderApp 0x000b8139 _TToFC12FeedReaderApp19TableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 89
7 UIKit 0x00e1d9a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
8 UIKit 0x00e1db14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
9 UIKit 0x00e2210e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
10 UIKit 0x00d510aa ___afterCACommitHandler_block_invoke + 15
11 UIKit 0x00d51055 _applyBlockToCFArrayCopiedToStack + 403
12 UIKit 0x00d50e76 _afterCACommitHandler + 532
13 CoreFoundation 0x0066e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
14 CoreFoundation 0x0066e2bf __CFRunLoopDoObservers + 399
15 CoreFoundation 0x0064c254 __CFRunLoopRun + 1076
16 CoreFoundation 0x0064b9d3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x0064b7eb CFRunLoopRunInMode + 123
18 GraphicsServices 0x043a15ee GSEventRunModal + 192
19 GraphicsServices 0x043a142b GSEventRun + 104
20 UIKit 0x00d33f9b UIApplicationMain + 1225
21 FeedReaderApp 0x000bc6ae top_level_code + 78
22 FeedReaderApp 0x000bc6eb main + 43
23 libdyld.dylib 0x026676d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
这是我的 UITableViewController 的代码,用于处理 table 单元格的 selection:
class TableViewController: UITableViewController, MWFeedParserDelegate {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
currentItem = self.items[indexPath.row] as MWFeedItem
let vc : AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("detailView")
self.showViewController(vc as UIViewController, sender: vc)
}
}
感谢您的帮助!
ios 7 没有 showViewController 方法,只存在于 iOS8
if (self.respondsToSelector(Selector("showViewController")))
{
self.showViewController(vc as UIViewController, sender: vc)
}
else if(self.navigationController.respondsToSelector(Selector("pushViewController")))
{
self.navigationController!.pushViewController(vs as UIViewController, animated: true)
}
我是 iOS 开发的新手,我在 Swift 中编写了一个 RSS 提要 reader。提要项显示在 UITableView 中。当我 select(触摸、单击)一个项目时,会显示一个新的 UIView,显示 selected 项目的提要描述。
它适用于 iOS8,但是当我尝试 iOS7 时,应用程序崩溃并且我得到以下输出:
2015-03-06 21:18:50.009 FeedReaderApp[9084:607] -[FeedReaderApp.TableViewController showViewController:sender:]: unrecognized selector sent to instance 0x7be8b100
2015-03-06 21:18:50.012 FeedReaderApp[9084:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FeedReaderApp.TableViewController showViewController:sender:]: unrecognized selector sent to instance 0x7be8b100'
*** First throw call stack:
(
0 CoreFoundation 0x006a61e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01c4d8e5 objc_exception_throw + 44
2 CoreFoundation 0x00743243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0069650b ___forwarding___ + 1019
4 CoreFoundation 0x006960ee _CF_forwarding_prep_0 + 14
5 FeedReaderApp 0x000b8068 _TFC12FeedReaderApp19TableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 1400
6 FeedReaderApp 0x000b8139 _TToFC12FeedReaderApp19TableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 89
7 UIKit 0x00e1d9a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
8 UIKit 0x00e1db14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
9 UIKit 0x00e2210e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
10 UIKit 0x00d510aa ___afterCACommitHandler_block_invoke + 15
11 UIKit 0x00d51055 _applyBlockToCFArrayCopiedToStack + 403
12 UIKit 0x00d50e76 _afterCACommitHandler + 532
13 CoreFoundation 0x0066e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
14 CoreFoundation 0x0066e2bf __CFRunLoopDoObservers + 399
15 CoreFoundation 0x0064c254 __CFRunLoopRun + 1076
16 CoreFoundation 0x0064b9d3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x0064b7eb CFRunLoopRunInMode + 123
18 GraphicsServices 0x043a15ee GSEventRunModal + 192
19 GraphicsServices 0x043a142b GSEventRun + 104
20 UIKit 0x00d33f9b UIApplicationMain + 1225
21 FeedReaderApp 0x000bc6ae top_level_code + 78
22 FeedReaderApp 0x000bc6eb main + 43
23 libdyld.dylib 0x026676d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
这是我的 UITableViewController 的代码,用于处理 table 单元格的 selection:
class TableViewController: UITableViewController, MWFeedParserDelegate {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
currentItem = self.items[indexPath.row] as MWFeedItem
let vc : AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("detailView")
self.showViewController(vc as UIViewController, sender: vc)
}
}
感谢您的帮助!
ios 7 没有 showViewController 方法,只存在于 iOS8
if (self.respondsToSelector(Selector("showViewController")))
{
self.showViewController(vc as UIViewController, sender: vc)
}
else if(self.navigationController.respondsToSelector(Selector("pushViewController")))
{
self.navigationController!.pushViewController(vs as UIViewController, animated: true)
}