본문 바로가기

프로그래밍/아이폰 프로그래밍

24. UIAlertView 사용하기


♨ UIAlertView를 사용하기 위해서는 다음과 같이 헤더파일에 델리게이트를 참조시켜야합니다.


@interface ContentViewController : UIViewController <UIAlertViewDelegate> {

    


}


- (IBAction)deleteMemo:(id)sender;





그리고 .m 파일에서 사용하면 됩니다.


- (IBAction)deleteMemo:(id)sender {

    

UIAlertView *alertView;

alertView = [[UIAlertView alloc] initWithTitle:@"MemoPad" message:nil delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];

[alertView setMessage:@"Do you want to delete the memo?"];

[alertView show];

[alertView release];

}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

// 사용자가 Yes 선택한 경우

if (buttonIndex == 1) {

MemoPadAppDelegate *appDelegate = (MemoPadAppDelegate *)[[UIApplication sharedApplication] delegate];

// 메모를 삭제한다.

[appDelegate deleteMemoFromDatabase];

// 현재 보고있던 메모가 삭제 되었으므로 목록보기 화면으로 돌아간다.

[self.navigationController popViewControllerAnimated:YES];

}

}