在这段代码中,我想将创建的字符串更改为整数,并希望将其用于进一步处理。我怎样才能做到这一点? 这里的recordId是EquoToString:@“1”,我想把这个字符串“1”改成整数然后想用它
-(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];
}
}
答案 0 :(得分:0)
你不需要这样做。只需使用NSString's intValue
消息。
您的代码将类似于:
if ([recordId intValue] == 1]) {
// do what you need when 1
} else if ([recordId intValue] == 0) {
// do what you need when 0
}
答案 1 :(得分:0)
[recordId intValue];
试试这个。