ITeye博客

iphone 确认框与提示框

wilent · 2012-08-25 23:35 · iphone · 移动开发 · Markdown

首先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];
	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。