2011-08-12 106 views
0

我对这个代码loginButton.enabled = YES;的最后一行接收SIGABRT错误。它今天早上工作,现在这个错误出现了。中止在iPhone模拟器

-(IBAction)login:(id)sender 
{ 
    UIButton *loginButton = (UIButton *)sender; 
    loginButton.enabled = NO; 
    NSString *filePath = [self dataFilePath]; 
    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
    { 
     NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath]; 
     NSString *nameString = [[NSString alloc] init]; 
     NSString *contactIdString = [[NSString alloc] init]; 
     NSString *genderString = [[NSString alloc] init]; 
     NSString *contactTypeString = [[NSString alloc] init]; 
     nameString = [array objectAtIndex:0]; 
     contactIdString = [array objectAtIndex:1]; 
     genderString = [array objectAtIndex:2]; 
     contactTypeString = [array objectAtIndex:3]; 

     self.name = nameString; 
     self.contactId = contactIdString; 
     self.gender = genderString; 
     self.contactType = contactTypeString; 
     [self.userArray removeAllObjects]; 
     [self performSelectorInBackground:@selector(sendData) withObject:nil]; 

     [nameString release]; 
     [contactIdString release]; 
     [genderString release]; 
     [contactTypeString release]; 

     UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logout:)]; 

     //[logoutButton setTitle:@"Logout"]; 
     [[self navigationItem] setRightBarButtonItem:logoutButton]; 
     [logoutButton release]; 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New User" message:@"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
    loginButton.enabled = YES; 
} 

这是错误转储。

2011-08-12 11:41:56.700 FaceConnect[1651:207] Reachability Flag Status: -R ------- networkStatusForFlags 
2011-08-12 11:41:59.247 FaceConnect[1651:207] selected first row 
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a0cf10 of class NSConcreteMutableData autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.344 FaceConnect[1651:207] -[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820 
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a108b0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06e70 of class NSConcreteMutableData autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06220 of class NSConcreteMutableData autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06ca0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e068c0 of class NSURL autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e061c0 of class NSMutableURLRequest autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e069e0 of class NSCFString autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06b30 of class NSCFString autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.345 FaceConnect[1651:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820' *** Call stack at first throw: (
     0 CoreFoundation  0x0249d919 __exceptionPreprocess + 185 
     1 libobjc.A.dylib  0x025eb5de objc_exception_throw + 47 
     2 CoreFoundation  0x0249f42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
     3 CoreFoundation  0x0240f116 ___forwarding___ + 966 
     4 CoreFoundation  0x0240ecd2_CF_forwarding_prep_0 + 50 
     5 FaceConnect   0x0000a7ea -[HubViewController login:] + 1802 
     6 UIKit    0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119 
     7 UIKit    0x0032b14b-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156 
     8 UIKit    0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119 
     9 UIKit    0x001ad6c8 -[UIControlsendAction:to:forEvent:] + 67 
     10 UIKit    0x001afb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] +527 
     11 UIKit    0x001ae6f7 -[UIControltouchesEnded:withEvent:] + 458 
     12 UIKit    0x001472ff -[UIWindow _sendTouchesForEvent:] + 567 
     13 UIKit    0x001291ec -[UIApplication sendEvent:] + 447 
     14 UIKit    0x0012dac4 _UIApplicationHandleEvent + 7495 
     15 GraphicsServices  0x02924afa PurpleEventCallback + 1578 
     16 CoreFoundation  0x0247edc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__+ 52 
     17 CoreFoundation  0x023df737__CFRunLoopDoSource1 + 215 
     18 CoreFoundation  0x023dc9c3 __CFRunLoopRun + 979 
     19 CoreFoundation  0x023dc280 CFRunLoopRunSpecific + 208 
     20 CoreFoundation  0x023dc1a1 CFRunLoopRunInMode + 97 
     21 GraphicsServices  0x029232c8 GSEventRunModal + 217 
     22 GraphicsServices  0x0292338d GSEventRun + 115 
     23 UIKit    0x00131b58 UIApplicationMain + 1160 
     24 FaceConnect   0x00001ac9 main + 121 
     25 FaceConnect   0x00001a45 start + 53 
     26 ???     0x00000001 0x0 + 1) 
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06a40 of class NSCFString autoreleased with no pool in place - just leaking 
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x6f4c0c0 of class NSCFString autoreleased with no pool in place - just leaking terminate called after throwing an instance of 'NSException' Current language: auto; currently objective-c 

我刚刚在我的iPhone上检查过它,并且应用程序没有崩溃。它只发生在模拟器上。

+0

是您loginbutton的RightBarButtonItem? –

+0

集NSZombieEnabled是的,它会告诉你正确的崩溃原因.. – PJR

+0

普利文是的,它是RightBarButtonItem。 – mintuz

回答

0

我猜的错误是从FaceConnect传播。请检查,它显示了很多泄漏和警告。

+0

有趣.....我通过将Bundle显示名称更改为FaceConnect而不是$(PRODUCT_NAME)来改变我的应用程序的名称吗? – mintuz

+0

是啊,很可能是,我只是伤心的通过看你的代码,以便涉足自己提高清洁方式代码,我没有完全看你的崩溃日志,因为它不是最初发布,感谢@Gilles编辑和后来我会显示你的崩溃日志。您可以随时使用** malloc_history **进行检查。 –

1

创建与分配/初始化空字符串,那么你改变它们的值由objectAtIndex:返回。这会导致指针指向自动发布的值。释放字符串后,应用程序将崩溃,因为保留计数将小于零。

+0

更新它,我从未有过的一个问题,它只是停止工作:S – mintuz

+0

检查我的问题,我有一点点的信息 – mintuz

+0

阅读我的答案更新它这是编写代码的更简洁的方式。 –

1
-(IBAction)login:(id)sender { 

    [(UIButton*) sender setEnabled:NO]; 

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { 
    NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath]; 

    NSString* name = [array objectAtIndex:0]; 
    NSString* contactId = [array objectAtIndex:1]; // depends if it is an integer then use int 
    NSString* gender = [array objectAtIndex:2]; 
    NSString* contactType = [array objectAtIndex:3]; 

    //[self.userArray removeAllObjects]; // what is your user array and why you are removing all the objects 
            // i could not find where you are setting the value for userArray 
    [self.userArray arrayWithObjects:self.name, self.contactId, self.gender,self.contactType, nil]; 

    [self performSelectorInBackground:@selector(sendData) withObject:nil]; 

    /*if (loginButton.selected == NO) { 
    // Represents user needs to login. Code for login user. 
    }else 
    { 
    [loginButton setTitle:@"Logout"]; 
    } 

    // toggle the login/logout states. 
    loginButton.selected = !loginButton.selected;*/ 

    UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logout:)]; 

    //[logoutButton setTitle:@"Logout"]; 
    [[self navigationItem] setRightBarButtonItem:logoutButton]; 
    [logoutButton release]; 
} 

else { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New User" message:@"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 

    [alert show]; 
    [alert release]; 

} 
[(UIButton*) sender setEnabled:YES]; 

} 

我找不到你在哪里设置userArray的价值,所以我想,我认为你要绑定的信息,以userArray和发送

-(id)sendData{ 
    //Do whatever you want to do with userArray 
} 


-(void)viewDidUnLoad{ 
     self.userarray = nil; 
     [super viewDidlUnload]; 
} 
-(void)dealloc{ 
    [userArray release]; 
    [super dealloc]; 
    } 
+0

它仍然在loginButton.enabled上出现相同的错误= YES – mintuz

+1

我喜欢Control-V的更干净的代码。代码更干净,最容易跟踪错误和控制代码。 – mysticboy59

+0

userarray是不同的东西,它用来为bk提供一个在线用户列表。 – mintuz