我正在制作应用程序,我正在使用Swft 3和Xcode 8.2 beta。我正在努力使用户能够从我的iOS项目中的SWRevealViewController访问社交媒体。单击社交媒体按钮时,应打开相应的应用程序。但是,当执行代码并打开iOS模拟器时,当我滑动以打开SWRevealViewController(菜单)时,应用程序崩溃。
完整错误消息:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TheGunnOracleApp.SocialMedia 0x7ffd0d50c0d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010212dd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000101b8f21e objc_exception_throw + 48
2 CoreFoundation 0x000000010212dc99 -[NSException raise] + 9
3 Foundation 0x000000010169db3f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000102e8e99f -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000103102c6e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001020d2b60 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x00000001031015f2 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000102e950d1 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000102e959f3 -[UIViewController loadView] + 177
10 UIKit 0x000000010311561c -[UITableViewController loadView] + 84
11 UIKit 0x0000000102e95d28 -[UIViewController loadViewIfRequired] + 201
12 UIKit 0x0000000102e9657c -[UIViewController view] + 27
13 TheGunnOracleApp 0x00000001014d50fb -[SWRevealViewController _deployForViewController:inView:] + 235
14 TheGunnOracleApp 0x00000001014d4f58 -[SWRevealViewController _deploymentForViewController:inView:appear:disappear:] + 136
15 TheGunnOracleApp 0x00000001014d48c1 -[SWRevealViewController _rearViewDeploymentForNewFrontViewPosition:] + 433
16 TheGunnOracleApp 0x00000001014d32f2 -[SWRevealViewController _setFrontViewPosition:withDuration:] + 82
17 TheGunnOracleApp 0x00000001014d26c6 __65-[SWRevealViewController _dispatchSetFrontViewPosition:animated:]_block_invoke + 70
18 TheGunnOracleApp 0x00000001014d1300 -[SWRevealViewController _enqueueBlock:] + 160
19 TheGunnOracleApp 0x00000001014d261b -[SWRevealViewController _dispatchSetFrontViewPosition:animated:] + 251
20 TheGunnOracleApp 0x00000001014d0154 -[SWRevealViewController setFrontViewPosition:animated:] + 148
21 TheGunnOracleApp 0x00000001014cffed -[SWRevealViewController revealToggleAnimated:] + 93
22 TheGunnOracleApp 0x00000001014d05df -[SWRevealViewController revealToggle:] + 63
23 UIKit 0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
24 UIKit 0x0000000103137971 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 149
25 UIKit 0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
26 UIKit 0x0000000102e7c344 -[UIControl sendAction:to:forEvent:] + 67
27 UIKit 0x0000000102e7c65d -[UIControl _sendActionsForEvents:withEvent:] + 444
28 UIKit 0x0000000102e7c7e7 -[UIControl _sendActionsForEvents:withEvent:] + 838
29 UIKit 0x0000000102e7b559 -[UIControl touchesEnded:withEvent:] + 668
30 UIKit 0x0000000102d63d5d -[UIWindow _sendTouchesForEvent:] + 2747
31 UIKit 0x0000000102d6544b -[UIWindow sendEvent:] + 4011
32 UIKit 0x0000000102d1254b -[UIApplication sendEvent:] + 371
33 UIKit 0x00000001034fda0f __dispatchPreprocessedEventFromEventQueue + 3248
34 UIKit 0x00000001034f6745 __handleEventQueue + 4879
35 CoreFoundation 0x00000001020d28e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
36 CoreFoundation 0x00000001020b7b0c __CFRunLoopDoSources0 + 556
37 CoreFoundation 0x00000001020b6ff6 __CFRunLoopRun + 918
38 CoreFoundation 0x00000001020b6a04 CFRunLoopRunSpecific + 420
39 GraphicsServices 0x0000000107e37a6f GSEventRunModal + 161
40 UIKit 0x0000000102cf4808 UIApplicationMain + 159
41 TheGunnOracleApp 0x00000001014f2d0f main + 111
42 libdyld.dylib 0x0000000105ddd68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
以下是社交媒体中每个按钮的代码。
注意:我删除了其他社交媒体的代码,因为Facebook最初没有工作:
import Foundation
import UIKit
class SocialMedia: UITableViewController{
@IBAction func facebookOpen(_ sender: Any) {
UIApplication.shared.open(NSURL(string: "https://www.facebook.com/gunnoracle")! as URL)
}
}
以下是我的Main.storyboard UITableViewController的截图:
答案 0 :(得分:0)
似乎问题不是由我刚试过的那段代码引起的,而是有效的。
当我滑动打开SWRevealViewController(菜单)时,应用程序崩溃了。
这可能是原因。你如何使用SWRevealViewController有问题。