您的位置:首页 > 其它

使用Xcode时遇到的一些小问题

2015-08-18 00:04 627 查看
今天在用Xcode写代码的时候突然发现了一个问题,于是就准备写一个文章来记录和总结一下在Xcode里面遇到的问题。这篇文章会经常补充。


在iOS模拟器启动时无法启动的问题。

这个问题很常见,几乎像我一样刚开始学iOS开发不久的新人们都会遇到。其实原因很简单,但是也很容易忽视。(在Stanford iOS开发的课里面也见到过。)这时候会在终端出现的码类似如下:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[test.ViewController didClickTestButton:]: unrecognized selector sent to instance 0x7feff247a680'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000108d3cc65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010a8a7bb7 objc_exception_throw + 45
2   CoreFoundation                      0x0000000108d440ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x0000000108c9a13c ___forwarding___ + 988
4   CoreFoundation                      0x0000000108c99cd8 _CF_forwarding_prep_0 + 120
5   UIKit                               0x00000001095dcd62 -[UIApplication sendAction:to:from:forEvent:] + 75
6   UIKit                               0x00000001096ee50a -[UIControl _sendActionsForEvents:withEvent:] + 467
7   UIKit                               0x00000001096ed8d9 -[UIControl touchesEnded:withEvent:] + 522
8   UIKit                               0x0000000109629958 -[UIWindow _sendTouchesForEvent:] + 735
9   UIKit                               0x000000010962a282 -[UIWindow sendEvent:] + 682
10  UIKit                               0x00000001095f0541 -[UIApplication sendEvent:] + 246
11  UIKit                               0x00000001095fdcdc _UIApplicationHandleEventFromQueueEvent + 18265
12  UIKit                               0x00000001095d859c _UIApplicationHandleEventQueue + 2066
13  CoreFoundation                      0x0000000108c70431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14  CoreFoundation                      0x0000000108c662fd __CFRunLoopDoSources0 + 269
15  CoreFoundation                      0x0000000108c65934 __CFRunLoopRun + 868
16  CoreFoundation                      0x0000000108c65366 CFRunLoopRunSpecific + 470
17  GraphicsServices                    0x000000010cd10a3e GSEventRunModal + 161
18  UIKit                               0x00000001095db8c0 UIApplicationMain + 1282
19  test                                0x0000000108b554e7 main + 135
20  libdyld.dylib                       0x000000010afdd145 start + 1
21  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException


这是因为缺少了某个控件的关联,如图:



我们只需要消除掉这个关联,然后重新添加关联即可。

Xcode警示找不到某个成员

这个是我今天遇到的问题,这个我个人认为是Xcode的一个bug吧。我的代码是这样的:

func givePeopleScore(forNumber num: Int, andScore score: Int) {
roll[num].score = (roll[num].score * roll[num].callCount + Double(score)) / Double(roll[num].callCount + 1)
}


(其中roll[num].score 为Double型,roll[num].callCount为Int型。)警示的根源其实在于Double型和Int型相乘, *运算符无法做到。所以只要类型转换即可, 即:

func givePeopleScore(forNumber num: Int, andScore score: Int) {
roll[num].score = (roll[num].score * Double(roll[num].callCount) + Double(score)) / Double(roll[num].callCount + 1)
}


settings.bundle 相关的settings没有在iOS模拟器里面显示(只显示了定位服务)。

我很诧异的发现了这个问题,我不知道其中的原因是什么,但是解决方法是:删除原有的app,再重新run一下,就可以看到了。但是,如果停止了之后再run,没有删除,那样就又看不到了。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xcode