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

今天在用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,没有删除,那样就又看不到了。。。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值