IBOutlet UITextView *readme;
[super viewDidLoad];
NSString *string = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"README" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
readme.text = string;
当我将标签项更改为其他时,此部分代码在UIApplicationMain中生成EXC_BAD_ACCESS。没有这个代码一切正常。 有什么想法吗?
NSZombieEnabled = YES,但是当我按下一步时,点就在同一位置。 IBOutlet作为参考出口连接到自述文件。这是一个堆栈。
0 libSystem.B.dylib calloc 1 libobjc.A.dylib NXHashInsert 2 libobjc.A.dylib
_NXHashRehashToCapacity 3 libobjc.A.dylib NXHashInsert 4 libobjc.A.dylib realizeClass(class_t*) 5 libobjc.A.dylib
_class_getNonMetaClass 6 libobjc.A.dylib _class_initialize 7 libobjc.A.dylib prepareForMethodLookup 8 libobjc.A.dylib lookUpMethod 9 libobjc.A.dylib
_class_lookupMethodAndLoadCache 10 libobjc.A.dylib objc_msgSend 11 UIKit -[UIWebDocumentView initSimpleHTMLDocumentWithStyle:editable:withFrame:withPreferences:] 12 UIKit -[UITextView commonInitWithWebDocumentView:isDecoding:] 13 UIKit -[UITextView initWithCoder:] 14 Foundation
_decodeObjectBinary 15 Foundation -[NSKeyedUnarchiver
_decodeArrayOfObjectsForKey:] 16 Foundation -[NSArray(NSArray) initWithCoder:] 17 Foundation
_decodeObjectBinary 18 Foundation _decodeObject 19 UIKit -[UIView initWithCoder:] 20 Foundation
_decodeObjectBinary 21 Foundation _decodeObject 22 UIKit -[UIRuntimeConnection initWithCoder:] 23 Foundation
_decodeObjectBinary 24 Foundation -[NSKeyedUnarchiver
_decodeArrayOfObjectsForKey:] 25 Foundation -[NSArray(NSArray) initWithCoder:] 26 Foundation
_decodeObjectBinary 27 Foundation _decodeObject 28 UIKit -[UINib instantiateWithOwner:options:] 29 UIKit
-[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] 30 UIKit -[UIViewController
_loadViewFromNibNamed:bundle:] 31 UIKit -[UIViewController loadView] 32 UIKit -[UIViewController view] 33 UIKit -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] 34 UIKit -[UITabBarController transitionFromViewController:toViewController:] 35 UIKit -[UITabBarController
_setSelectedViewController:] 36 UIKit -[UITabBarController
_tabBarItemClicked:] 37 UIKit -[UIApplication sendAction:to:from:forEvent:] 38 UIKit -[UITabBar
_sendAction:withEvent:] 39 UIKit -[UIApplication sendAction:to:from:forEvent:] 40 UIKit -[UIControl sendAction:to:forEvent:] 41 UIKit
-[UIControl(Internal) _sendActionsForEvents:withEvent:] 42 UIKit -[UIControl sendActionsForControlEvents:] 43 UIKit -[UIApplication sendAction:to:from:forEvent:] 44 UIKit -[UIControl sendAction:to:forEvent:] 45 UIKit
-[UIControl(Internal) _sendActionsForEvents:withEvent:] 46 UIKit -[UIControl touchesEnded:withEvent:] 47 UIKit
-[UIWindow _sendTouchesForEvent:] 48 UIKit -[UIApplication sendEvent:] 49 UIKit _UIApplicationHandleEvent 50 GraphicsServices PurpleEventCallback 51 CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 52 CoreFoundation
__CFRunLoopDoSource1 53 CoreFoundation __CFRunLoopRun 54 CoreFoundation CFRunLoopRunSpecific 55 CoreFoundation CFRunLoopRunInMode 56 GraphicsServices GSEventRunModal 57 GraphicsServices GSEventRun 58 UIKit UIApplicationMain 59 snow iphone main /Users/mac/Documents/Programming/Projects/snow
- head/snow iphone/main.m:13 60 snow iphone start
解
UIImage *imageForEvents = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"events" ofType:@"png"]];
UITabBarItem *eventsBar = [[UITabBarItem alloc] initWithTitle:@"Events" image:imageForEvents tag:0];
events.tabBarItem = eventsBar;
[eventsBar release];
这个代码的和平是在表视图控制器区域中创建的。在我将其更改为appdelegate后,错误消失了。 奇怪的是调试没有显示适当的代码行。
答案 0 :(得分:2)
设置NSZombieEnabled以检查哪个对象负责EXC_BAD_ACCESS。
答案 1 :(得分:1)
你确定自述文件IBOutlet在Interface Builder中完全连接了吗?
NSLog(@"className of readme is \"%@\".", [readme className]);
BTW,UITextView文本属性有copy属性,自动释放的字符串会很好。
NSString *string = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"README" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
答案 2 :(得分:0)
您发布的代码不应导致EXC_BAD_ACCESS。由于EXC_BAD_ACCESS是当你尝试向已经解除分配的类发送消息时发生的事情,我会在你的应用程序中查找你要么释放一些东西而不是将指针设置为nil,或者你应该保留一些东西而不是在做什么如此。