2011-12-05 183 views
0

在此代碼中,我想更改字符串創建爲整數,並希望將其用於進一步處理。我怎樣才能做到這一點? 這裏的recordId isEqualToString:@「1」,我想改變這個字符串「1」爲整數,然後想用它將字符串更改爲整數iphone

-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ 

    if (foundRecordId) { 
     NSLog(@"didEndElement: %@", recordId);  
    } 

    if ([recordId isEqualToString:@"1"]) { 

     NSLog(@"Only 1 account"); 

     MainScreenController *mainScreen1 = [[MainScreenController alloc] initWithNibName:@"MainScreen" bundle:nil ]; 

     self.mainScreen = mainScreen1; 

     [self.view addSubview: mainScreen1.view];   
    } 

    else if ([recordId isEqualToString:@"0"]){ 

     NSLog(@"Accounts more than 1"); 

     ChooseAccountsController *chooseAccount = [[ChooseAccountsController alloc] initWithNibName:@"ChooseAccountsController" bundle:nil]; 
     self.chooseAcc = chooseAccount; 
     [self.view addSubview:chooseAccount.view];  
    } 

} 

回答

1

您不必這樣做。只需使用NSString'sintValue消息。

您的代碼將是這樣的:

if ([recordId intValue] == 1]) { 
    // do what you need when 1 
} else if ([recordId intValue] == 0) { 
    // do what you need when 0 
} 
+0

非常感謝你:) – AppDeveloper