首页 文章

iPhone - 从touchesMovedwithEvent更新NSMutablearray的第n个对象的属性

提问于
浏览
0

iPhone - update the property of nth object of a NSMutablearray的早期帖子中,我得到了一些在viewDidLoad中有效的东西但是当我尝试使用几乎相同的代码 - (void)touchesMoved:(NSSet *)触及withEvent:(UIEvent *)事件然后应用程序崩溃 .

@接口

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崩溃线程:0调度队列: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主96(的main.m:14)17 MJA 0x00002b75从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三十

线程2:0 WebThread 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(无效*) 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 Foundation 0x0008b102 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 398 7 Foundation 0x00055cf4 -[NSThread main] + 81 8 Foundation 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 select $ 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

3 回答

  • 0

    请注意崩溃日志的顶部;

    异常类型:EXC_BAD_ACCESS(SIGSEGV)异常代码:KERN_INVALID_ADDRESS位于0x0000000032200002崩溃线程:0调度队列:com.apple.main-thread

    任何时候你看到 EXC_BAD_ACCESS 你的第一个想法应该是'I'已经发布了一些对象' .

    正如@csch所说,你应该打开僵尸,看看告诉你什么信息 .

    我的猜测是 iconsMutableArray 是通过像这样的一段代码初始化的;

    iconsMutableArray = [NSMutableArray array];
    

    分配但不保留(阅读内存管理指南here) .

    此外,您应该使用手势识别器,而不是自己实现触摸处理 . 阅读here .

  • 2

    看起来 iconsMutableArray 已经在某处发布,或者从未设置过 . 也许你把它设置为一个自动释放的对象并忘了 retain 它?

  • 0

    我建议用多行重写代码,然后逐步调试,看看图像或数组是否为零 . 您也可能正在访问超出范围的索引 .

    here所述,还将NSZombieEnabled设置为YES . 这可能会给您更详细的错误消息 .

相关问题