IOS笔记 - UIActionSheet

	UIActionSheet *actionSheet = [[UIActionSheet alloc]
					// initWithTitle:是显示的标题,显示在操作表的顶部。
					initWithTitle:@"Are you sure?"
					// delegate:是操作表的委托,将在该表上的按钮被按下时收到通知,
					// 更确切地说,委托的ActionSheet:didDismissWithButtonIndex:
					// actionSheet:didDismisswithButtonIndex:方法将被调用。
					delegate:self
					// cancelButtonTitle:是取消按钮的标题,用户可以通过点击此按钮表明不希望继续操作。
					cancelButtonTitle:@"No way!"
					// destructiveButtonTitle:确定按钮的标题,同上相反。
					destructiveButtonTitle:@"Yes,I'm sure!"
					/ otherButtonTitle:是用于指定希望在表单上现实的其他按钮的数量,该参数可以使用各种值
					// otherButtonTitle:@"Foo",@"Bar",nil];
					otherButtonTitles:nil];
	[actionSheet showInView:self.view];
	[actionSheet release];


关于delegate,

-(void) actionSheet:(UIActionSheet *) actionSheet 
didDismissWithButtonIndex:(NSInteger) buttonIndex
{
	NSLog(@"buttonIndex is %d",buttonIndex);
	if (buttonIndex != [actionSheet cancelButtonIndex]) {
		NSString *msg = nil ;
		if (nameField.text.length) {
			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 done" 
							  message:msg 
							  delegate:self 
							  cancelButtonTitle:@"Phew!" 
							  otherButtonTitles:nil];
		[alert show];
		[alert release];
		[msg release];

	}
}

Instance Methods

actionSheet:clickedButtonAtIndex:

Sent to the delegate when the user clicks a button on an action sheet.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet containing the button.

buttonIndex

The position of the clicked button. The button indices start at 0.

Discussion

The receiver is automatically dismissed after this method is invoked.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheet:didDismissWithButtonIndex:

Sent to the delegate after an action sheet is dismissed from the screen.

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet that was dismissed.

buttonIndex

The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion

This method is invoked after the animation ends and the view is hidden.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheet:willDismissWithButtonIndex:

Sent to the delegate before an action sheet is dismissed.

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet that is about to be dismissed.

buttonIndex

The index of the button that was clicked. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion

This method is invoked before the animation begins and the view is hidden.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheetCancel:

Sent to the delegate before an action sheet is canceled.

- (void)actionSheetCancel:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that will be canceled.

Discussion

If the action sheet’s delegate does not implement this method, clicking the cancel button is simulated and the action sheet is dismissed. Implement this method if you need to perform some actions before an action sheet is canceled. An action sheet can be canceled at any time by the system—for example, when the user taps the Home button. TheactionSheet:willDismissWithButtonIndex: and actionSheet:didDismissWithButtonIndex: methods are invoked after this method.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

didPresentActionSheet:

Sent to the delegate after an action sheet is presented to the user.

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that was displayed.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

willPresentActionSheet:

Sent to the delegate before an action sheet is presented to the user.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that is about to be displayed.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

Instance Methods

actionSheet:clickedButtonAtIndex:

Sent to the delegate when the user clicks a button on an action sheet.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet containing the button.

buttonIndex

The position of the clicked button. The button indices start at 0.

Discussion

The receiver is automatically dismissed after this method is invoked.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheet:didDismissWithButtonIndex:

Sent to the delegate after an action sheet is dismissed from the screen.

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet that was dismissed.

buttonIndex

The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion

This method is invoked after the animation ends and the view is hidden.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheet:willDismissWithButtonIndex:

Sent to the delegate before an action sheet is dismissed.

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
Parameters
actionSheet

The action sheet that is about to be dismissed.

buttonIndex

The index of the button that was clicked. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion

This method is invoked before the animation begins and the view is hidden.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

actionSheetCancel:

Sent to the delegate before an action sheet is canceled.

- (void)actionSheetCancel:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that will be canceled.

Discussion

If the action sheet’s delegate does not implement this method, clicking the cancel button is simulated and the action sheet is dismissed. Implement this method if you need to perform some actions before an action sheet is canceled. An action sheet can be canceled at any time by the system—for example, when the user taps the Home button. TheactionSheet:willDismissWithButtonIndex: and actionSheet:didDismissWithButtonIndex: methods are invoked after this method.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

didPresentActionSheet:

Sent to the delegate after an action sheet is presented to the user.

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that was displayed.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

willPresentActionSheet:

Sent to the delegate before an action sheet is presented to the user.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
Parameters
actionSheet

The action sheet that is about to be displayed.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIActionSheet.h

原文地址:https://www.cnblogs.com/waddell/p/3405520.html