竊聽按鈕我有這個代碼在我的應用程序運行,而現在在iOS 6崩潰我的應用程序:檢索的UIAlertView中
// Another method
[NSThread detachNewThreadSelector:@selector(askServerForNFeID)
toTarget:self withObject:nil];
- (void)askServerForNFeID {
if ([response isEqualToString:@"XXXX"]) {
NSString *responseMessage = [NSString stringWithFormat:
NSLocalizedString(@"Autorizado o Uso da NFe\n para chave:\n%@", @""),
[invoiceInfo NFeID]];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Sefaz respondeu:", @"")
message:responseMessage
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
我已經瞭解到,呼籲從第二個線程警報導致崩潰,和所以我改變了我的代碼來調用從主線程像這樣的警告:
if ([response isEqualToString:@"XXXX"]) {
[self performSelectorOnMainThread:@selector(showAlertHelper:)
withObject:[[NSArray alloc] initWithObjects:
NSLocalizedString(@"Não posso seguir em frente", @""),
NSLocalizedString(@"Você usou .....", @""), @"Fechar", @"Comprar", nil]
waitUntilDone:YES];
注意我解析標題,消息和按鈕的列表showAlertHelper ...
-(void)showAlertHelper:(NSArray*)theArray{
if ([[theArray objectAtIndex:3] isEqualToString:@""]) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:[theArray objectAtIndex:0]
message:[theArray objectAtIndex:1]
delegate:nil
cancelButtonTitle:[theArray objectAtIndex:2]
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:[theArray objectAtIndex:0]
message:[theArray objectAtIndex:1]
delegate:nil
cancelButtonTitle:[theArray objectAtIndex:2]
otherButtonTitles:[theArray objectAtIndex:3], nil];
[alertView show];
[alertView release];
}
}
現在我的問題是,我有這個處理程序來捕獲按鈕,竊聽,它不再工作。它只是不叫:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:NSLocalizedString(@"Comprar", @"")]) {
// Do stuff to buy credits...
} else if ([title isEqualToString:NSLocalizedString(@"Fechar", @"")]) {
NSLog(@"Fechar was selected.");
}
else if ([title isEqualToString:NSLocalizedString(@"Criar conta", @"")]) {
// Do stuff to create an account...
}
}
謝謝你,謝謝你這麼多。有用... – fundidor