iphone 确认框与提示框

   首先Controller需要遵守UIActionSheetDelegate协议,如:

@interface SampleController : UIViewController<UIActionSheetDelegate> 

   Controller实现中可以这样触发确认框:

   UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure?"
									        delegate:self
										cancelButtonTitle:@"No way!"
										destructiveButtonTitle:@"Yes,I'm Sure!"
										otherButtonTitles:nil
					        ];
   [actionSheet showInView:self.view];
   [actionSheet release];

    Controller确认框事件:

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
	if(buttonIndex !=[actionSheet cancelButtonIndex]){
		NSString *msg = nil;
		if(nameField.text.length>0){
			msg = [[NSString alloc] initWithFormat:@"You can breathe easy ,%@,everything went OK>",nameField.text];
		}else{
			msg = @"You can breathe easy,everything went OK.";
		}
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"something was" message:msg delegate:self cancelButtonTitle:@"phew!" otherButtonTitles:nil];
		[alert show];
		[alert release];
		[msg release];
	}
}
 

猜你喜欢

转载自wilent.iteye.com/blog/1663000