我正在Swift中编写一个跟踪棒球比赛的应用程序。我需要编辑20多个标签。我不断收到“无法识别的选择器发送到实例”错误。我在每个UILabel插座上都设置了断点,它在第二次绕过第二次时崩溃了。这是我的应用程序类:
var home_scores = [Int]()
var away_scores = [Int]()
var player_list = [String]()
var inning = 1
var topInning = true
var Strikes = 0
var balls = 0
var outs = 0
//Outlets for most variable text
@IBOutlet var PlayerList: UITableView!
@IBOutlet var StrikesText: UILabel!
@IBOutlet var BallsText: UILabel!
@IBOutlet var OutsText: UILabel!
@IBOutlet var InningText: UILabel!
@IBOutlet var InnSideText: UILabel!
@IBOutlet var BatterName: UILabel!
//Outlets for score text... its a lot of outlets
//away
@IBOutlet var away1st: UILabel!
@IBOutlet var away2nd: UILabel! //crashes after a breakpoint here
@IBOutlet var away3rd: UILabel!
@IBOutlet var away4th: UILabel!
@IBOutlet var away5th: UILabel!
@IBOutlet var away6th: UILabel!
@IBOutlet var away7th: UILabel!
@IBOutlet var away8th: UILabel!
@IBOutlet var away9th: UILabel!
//home
@IBOutlet var home1st: UILabel!
@IBOutlet var home2nd: UILabel!
@IBOutlet var home3rd: UILabel!
@IBOutlet var home4th: UILabel!
@IBOutlet var home5th: UILabel!
@IBOutlet var home6th: UILabel!
@IBOutlet var home7th: UILabel!
@IBOutlet var home8th: UILabel!
@IBOutlet var home9th: UILabel!
func displayScores() {
away1st.text = String(away_scores[0])
away2nd.text = String(away_scores[1])
away3rd.text = String(away_scores[2])
away4th.text = String(away_scores[3])
away5th.text = String(away_scores[4])
away6th.text = String(away_scores[5])
away7th.text = String(away_scores[6])
away8th.text = String(away_scores[7])
away9th.text = String(away_scores[8])
home1st.text = String(home_scores[0])
home2nd.text = String(home_scores[1])
home3rd.text = String(home_scores[2])
home4th.text = String(home_scores[3])
home5th.text = String(home_scores[4])
home6th.text = String(home_scores[5])
home7th.text = String(home_scores[6])
home8th.text = String(home_scores[7])
home9th.text = String(home_scores[8])
}
@IBAction func hitStrike() {
Strikes += 1
}
这是错误:
2016-11-10 14:00:30.463 Base Tracker iPad[5992:325296] -[UILabel longLongValue]: unrecognized selector sent to instance 0x7fcaf1601c90
Process 5992 resuming
2016-11-10 14:00:30.538 Base Tracker iPad[5992:325296] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel longLongValue]: unrecognized selector sent to instance 0x7fcaf1601c90'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105ab534b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102dc921e objc_exception_throw + 48
2 CoreFoundation 0x0000000105b24f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000105a3ac15 ___forwarding___ + 1013
4 CoreFoundation 0x0000000105a3a798 _CF_forwarding_prep_0 + 120
5 Foundation 0x0000000102953faf _NSSetLongLongValueForKeyWithMethod + 63
6 Foundation 0x00000001028d926f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
7 UIKit 0x00000001034324ef -[UIViewController setValue:forKey:] + 88
8 UIKit 0x00000001036a679e -[UIRuntimeOutletConnection connect] + 109
9 CoreFoundation 0x0000000105a5a590 -[NSArray makeObjectsPerformSelector:] + 256
10 UIKit 0x00000001036a5122 -[UINib instantiateWithOwner:options:] + 1867
11 UIKit 0x0000000103438c21 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
12 UIKit 0x0000000103439543 -[UIViewController loadView] + 177
13 UIKit 0x0000000103439878 -[UIViewController loadViewIfRequired] + 201
14 UIKit 0x000000010343a0cc -[UIViewController view] + 27
15 UIKit 0x0000000103acd4be -[UIPageViewController _setViewControllers:withScrollInDirection:animated:completion:] + 591
16 UIKit 0x0000000103acd744 -[UIPageViewController setViewControllers:direction:animated:completion:] + 269
17 Base Tracker iPad 0x00000001027d0531 _TFC17Base_Tracker_iPad20MyPageViewController11viewDidLoadfT_T_ + 2609
18 Base Tracker iPad 0x00000001027d07f2 _TToFC17Base_Tracker_iPad20MyPageViewController11viewDidLoadfT_T_ + 34
19 UIKit 0x0000000103439c99 -[UIViewController loadViewIfRequired] + 1258
20 UIKit 0x000000010343a0cc -[UIViewController view] + 27
21 UIKit 0x0000000103d04bce __67-[UIStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 496
22 UIKit 0x0000000103a72fbd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
23 UIKit 0x0000000103a72dcd -[UIStoryboardSegueTemplate _perform:] + 82
24 UIKit 0x0000000103a7308f -[UIStoryboardSegueTemplate perform:] + 156
25 UIKit 0x0000000103439a7e -[UIViewController loadViewIfRequired] + 719
26 UIKit 0x000000010343a0cc -[UIViewController view] + 27
27 UIKit 0x0000000103303c51 -[UIWindow addRootViewControllerViewIfPossible] + 71
28 UIKit 0x00000001033043a2 -[UIWindow _setHidden:forced:] + 293
29 UIKit 0x0000000103317cb5 -[UIWindow makeKeyAndVisible] + 42
30 UIKit 0x0000000103290c89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
31 UIKit 0x0000000103296de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
32 UIKit 0x0000000103293f69 -[UIApplication workspaceDidEndTransaction:] + 188
33 FrontBoardServices 0x0000000107179723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
34 FrontBoardServices 0x000000010717959c -[FBSSerialQueue _performNext] + 189
35 FrontBoardServices 0x0000000107179925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
36 CoreFoundation 0x0000000105a5a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
37 CoreFoundation 0x0000000105a3f59c __CFRunLoopDoSources0 + 556
38 CoreFoundation 0x0000000105a3ea86 __CFRunLoopRun + 918
39 CoreFoundation 0x0000000105a3e494 CFRunLoopRunSpecific + 420
40 UIKit 0x00000001032927e6 -[UIApplication _run] + 434
41 UIKit 0x0000000103298964 UIApplicationMain + 159
42 Base Tracker iPad 0x00000001027d79bf main + 111
43 libdyld.dylib 0x00000001069e268d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
导致错误的原因是什么?我已经看到它可能是由重用的内存引起的,但这只是在应用程序加载时。
答案 0 :(得分:-1)
如果在您的视图控制器中连接了storyboard / nib文件中的某个标签,并且之后视图控制器中与该标签的连接相对应的变量已被删除,则会发生这种情况。这可能会为storyboard / nib文件中的标签留下悬空引用。
我会说检查storyboard / nib文件中的每个UI元素,看看是否有任何你没有在相应的视图控制器中引用的变量名。