在用户单击 UIAlertview 上的按钮后,我尝试使用电话应用程序拨打号码。手机应用确实打开了,但在单击 UIAlertview 上的按钮后,原始应用立即崩溃。有人知道原因吗?我确实试图确保我发布了应该发布的所有内容。谢谢!下面是代码:
-(IBAction)dialButtonPressed:(UIButton *)numberButton
{
if ([company isEqualToString:@"Not Found"]==true){
message = [[UIAlertView alloc] initWithTitle:@"Sorry"
message:@"No replace number found. Would you like to dial anyway?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
message.tag = 0;
if(phoneLinkString)
{
[phoneLinkString release];
phoneLinkString = nil;
}
[message show];
[message autorelease];
phoneLinkString = [[NSString stringWithFormat:@"tel:%@",replace]retain];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
[self release];
message = nil;
if(message.tag == 0 && buttonIndex == 1){
NSURL *phoneLinkURL = [NSURL URLWithString:phoneLinkString];
[[UIApplication sharedApplication] openURL:phoneLinkURL];
}
- (void)dealloc {
[phoneNumberString release];
[phoneNumberLabel release];
[self release];
[message release];
[super dealloc];
}
最新代码
-(IBAction)dialButtonPressed:(UIButton *)numberButton
{
if ([company isEqualToString:@"Not Found"]==true){
message = [[UIAlertView alloc] initWithTitle:@"Sorry"
message:@"No replace number found. Would you like to dial anyway?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
message.tag = 1;
if(phoneLinkString)
{
[phoneLinkString release];
phoneLinkString = nil;
}
[message show];
[message autorelease];
phoneLinkString = [[NSString stringWithFormat:@"tel:%@",replace]retain];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(message.tag == 1 && buttonIndex == 1){
NSURL *phoneLinkURL = [NSURL URLWithString:phoneLinkString];
[[UIApplication sharedApplication] openURL:phoneLinkURL];
message = nil;
}
}
- (void)dealloc {
[phoneNumberString release];
[phoneNumberLabel release];
[super dealloc];
}
但单击 UIAlertview 上的按钮后它仍然崩溃。错误是 0x3beb85b0: ldr r3, [r4, #8] EXC_BAD_ACCESS (code=1, address=0x7269634f) 任何帮助将不胜感激。谢谢!