我一直在尝试解决我的 iOS 应用程序中涉及 rangeOfString 的错误数小时,最终能够追踪我的应用程序崩溃的位置。我的应用程序将 TextViewA 设置为 MainTextView 的前半部分。应该添加什么if语句来检查nil?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
*** First throw call stack:
.
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
..................................................... ..................................................
现在没有可用于编程的内存:调用 malloc 不安全
2013-01-04 14:30:58.138 类型 [7279:c07] 分隔符:(空)
2013-01-04 14:30:58.138 类型[7279:c07] mainTextView: ; 层 = ; contentOffset: {0, 0} > 2013-01-04 14:30:58.139 Type[7279:c07] mainTextView.text: TESTTTTTTT f f.
2013-01-04 14:30:58.142 类型 [7279:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
*首先抛出调用栈:
(0x1a5d012 0x1882e7e 0x1a5cdeb 0xf78688 0xf87d88 0xfd05df 0x165ec 0x15dc6 0x1fd7b 0x56d8d5 0x56db3d 0xf74e83 0x1a1c376 0x1a1be06 0x1a03a82 0x1a02f44 0x1a02e1b 0x221d7e3 0x221d668 0x4be65c 0x2c5d 0x2b85)
libc++abi.dylib:终止调用抛出异常(gdb)