我試圖在用戶點擊UIAlertview上的按鈕後用手機應用程序撥號。手機應用程序確實打開,但點擊UIAlertview上的按鈕後,原來的應用程序立即崩潰。有誰知道原因?我確實試圖確保我發佈了應該發佈的所有內容。謝謝!下面是代碼:iOS應用程序在點擊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(代碼= 1,地址= 0x7269634f)任何幫助,將不勝感激。謝謝!
您的項目是否使用ARC? – rockstarberlin
從任何地方移除'[self release]'並嘗試 –
@rockstarberlin如果您看到代碼調用'retain','release'或'autorelease',那麼項目不能使用ARC。 – rmaddy