实现方法和操作表十分类似,先在类定义的时候加上UIAlertViewDelegate,用于以后处理按钮事件。
@interface testController : UIViewController <UIAlertViewDelegate> {...}
调用方法如下
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@“Message displayed" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; [alert show]; //显示 [alert release];
处理事件的方法为实现UIAlertViewDelegate的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *newText = [[NSString alloc] initWithFormat:@"%d", buttonIndex]; leftLabel.text = newText; [newText release]; }