在iPhone - update the property of nth object of a NSMutablearray的早期帖子中,我得到了一些在viewDidLoad中有效的东西,但当我尝试在 - (void)中使用几乎相同的代码时,touchesMoved:(NSSet *)触及withEvent:(UIEvent *)事件然后应用程序崩溃。
@interface
int activeItem;
int startFrom;
NSMutableArray *iconsMutableArray;
NSMutableArray *textsMutableArray;
然后
@property int activeItem;
@property int startFrom;
- (NSMutableArray *)iconsMutableArray;
- (NSMutableArray *)textsMutableArray;
@synthesize activeItem;
@synthesize startFrom;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
activeItem = (int)startFrom + (int)round(animationEndTo/AngleForEachItem);
[[iconsMutableArray objectAtIndex:activeItem] setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Guide-Icon-%d_Active.png", activeItem]]];
}
但我的应用程序无法更新UIIMageView并崩溃而不显示任何错误消息。 谁能帮帮我吗? 提前谢谢。
以下是崩溃报告:
异常类型:EXC_BAD_ACCESS(SIGSEGV) 例外代码:KERN_INVALID_ADDRESS位于0x0000000032200002 Crashed Thread:0 Dispatch queue:com.apple.main-thread
特定应用信息: objc_msgSend()选择器名称:objectAtIndex: iPhone模拟器238.2,iPhone OS 4.3(iPad / 8F192) iPhone模拟器238.2,iPhone OS 4.3(iPad / 8F192)
线程0崩溃:调度队列:com.apple.main-thread 0 libobjc.A.dylib 0x0197a09f objc_msgSend + 19 1 ??? 0x00229810 OBJC_CLASS _ $ _ NSNumber + 0 2 UIKit 0x003b90f4 forwardMethod2 + 92 3 UIKit 0x003b90f4 forwardMethod2 + 92 4 UIKit 0x0030fd97 - [UIWindow _sendTouchesForEvent:] + 481 5 UIKit 0x002f0c37 - [UIApplication sendEvent:] + 447 6 UIKit 0x002f5f2e _UIApplicationHandleEvent + 7576 7 GraphicsServices 0x01e87992 PurpleEventCallback + 1550 8 CoreFoundation 0x017f5944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 9 CoreFoundation 0x01755cf7 __CFRunLoopDoSource1 + 215 10 CoreFoundation 0x01752f83 __CFRunLoopRun + 979 11 CoreFoundation 0x01752840 CFRunLoopRunSpecific + 208 12 CoreFoundation 0x01752761 CFRunLoopRunInMode + 97 13 GraphicsServices 0x01e861c4 GSEventRunModal + 217 14 GraphicsServices 0x01e86289 GSEventRun + 115 15 UIKit 0x002f9c93 UIApplicationMain + 1160 16 MJA 0x00002bde main + 96(main.m:14) 17 MJA 0x00002b75 start + 53
主题1: 0 libSystem.B.dylib 0x9119d922 kevent + 10 1 libdispatch_sim.dylib 0x01d92f36 _dispatch_mgr_invoke + 237 2 libdispatch_sim.dylib 0x01d93333 _dispatch_queue_invoke + 162 3 libdispatch_sim.dylib 0x01d93593 _dispatch_worker_thread2 + 261 4 libSystem.B.dylib 0x9119cd21 _pthread_wqthread + 390 5 libSystem.B.dylib 0x9119cb66 start_wqthread + 30
线程2:WebThread 0 libSystem.B.dylib 0x9117709a mach_msg_trap + 10 1 libSystem.B.dylib 0x91177807 mach_msg + 68 2 CoreFoundation 0x017f5d86 __CFRunLoopServiceMachPort + 150 3 CoreFoundation 0x01752e74 __CFRunLoopRun + 708 4 CoreFoundation 0x01752840 CFRunLoopRunSpecific + 208 5 CoreFoundation 0x01752761 CFRunLoopRunInMode + 97 6 WebCore 0x02f13913 RunWebThread(void *)+ 499 7 libSystem.B.dylib 0x911a47fd _pthread_start + 345 8 libSystem.B.dylib 0x911a4682 thread_start + 34
主题3: 0 libSystem.B.dylib 0x9117709a mach_msg_trap + 10 1 libSystem.B.dylib 0x91177807 mach_msg + 68 2 CoreFoundation 0x017f5d86 CFRunLoopServiceMachPort + 150 3 CoreFoundation 0x01752e74 __CFRunLoopRun + 708 4 CoreFoundation 0x01752840 CFRunLoopRunSpecific + 208 5 CoreFoundation 0x01752761 CFRunLoopRunInMode + 97 6基金会0x0008b102 + [NSURLConnection(NSURLConnectionReallyInternal)_resourceLoadLoop:] + 398 7基础0x00055cf4 - [NSThread main] + 81 8基础0x00055c80 __NSThread__main + 1387 9 libSystem.B.dylib 0x911a47fd _pthread_start + 345 10 libSystem.B.dylib 0x911a4682 thread_start + 34
主题4:com.apple.CFSocket.private 0 libSystem.B.dylib 0x91196066选择$ DARWIN_EXTSN + 10 1 CoreFoundation 0x017872bc __CFSocketManager + 812 2 libSystem.B.dylib 0x911a47fd _pthread_start + 345 3 libSystem.B.dylib 0x911a4682 thread_start + 34
线程0与X86线程状态(32位)崩溃: eax:0x05e0e840 ebx:0x05a0ef11 ecx:0x05a05484 edx:0x05e6b200 edi:0x32200002 esi:0x00229810 ebp:0xbfffd728 esp:0xbfffd6c4 ss:0x0000001f efl:0x00010202 eip:0x0197a09f cs:0x00000017 ds:0x0000001f es:0x0000001f fs:0x00000000 gs:0x00000037 cr2:0x32200002
答案 0 :(得分:2)
请注意崩溃日志的顶部;
异常类型:EXC_BAD_ACCESS (SIGSEGV)例外代码: KERN_INVALID_ADDRESS在 0x0000000032200002崩溃的线程:0 Dispatch queue:com.apple.main-thread
任何时候你看到EXC_BAD_ACCESS
你的第一个想法应该是'我已经释放了一些对象'。
正如@csch所说,你应该打开僵尸并查看告诉你的信息。
我的猜测是iconsMutableArray
是通过像这样的一段代码初始化的;
iconsMutableArray = [NSMutableArray array];
分配但不保留的(阅读内存管理指南here)。
此外,您应该使用手势识别器,而不是自己实施触摸处理。阅读here。
答案 1 :(得分:0)
看起来iconsMutableArray
已在某处释放,或者从未设置过。也许您将其设置为自动释放的对象并忘记retain
它?
答案 2 :(得分:0)
我建议在多行中重写代码,然后逐步调试,看看图像或数组是否为零。您也可能正在访问超出范围的索引。
同样将NSZombieEnabled设置为YES,如here所述。这可能会给您更详细的错误消息。