2011-08-12 104 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