UIActionSheet实例,显示简单菜单

UIActionSheet实例,显示简单菜单。
采用滑动方式呈现在屏幕上,等待用户响应

显示菜单的方法:
1、showInView
2、showFromToolBar:和showFromTabBar

视图控制类需要是现实协议接口UIActionSheetDelegate
 
  
@interface HelloController : UIViewController < UIActionSheetDelegate >
@end


主要实现代码:
 
  
- ( void )actionSheet:(UIActionSheet * )actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
printf(
" User Pressed Button %d\n " , buttonIndex + 1 );
[actionSheet release];
}

- ( void ) presentSheet
{
UIActionSheet
* menu = [[UIActionSheet alloc]
initWithTitle:
@" File Management "
delegate :self
cancelButtonTitle:
@" Cancel "
destructiveButtonTitle:
@" Delete File "
otherButtonTitles:
@" Rename File " , @" Email File " , nil];
[menu showInView:self.view];
}


类学习

UIActionSheet类

继承UIView

Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.

使用UIActionSheet类呈现给用户一系列交替选项用于决定如何处理所给的任务。你也可以使用动作表来提示用户确认具有潜在危险的动作。动作表包含可选标题和1个或多个按钮,每个按钮对应响应所给的动作。

Creating Action Sheets

    – initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:

Setting Properties

      delegate  property
      title  property
      visible  property
      actionSheetStyle  property

Configuring Buttons

    – addButtonWithTitle:
      numberOfButtons  property
    – buttonTitleAtIndex:
      cancelButtonIndex  property
      destructiveButtonIndex  property
      firstOtherButtonIndex  property

Presenting the Action Sheet

    – showFromTabBar:
    – showFromToolbar:
    – showInView:
    – showFromBarButtonItem:animated:
    – showFromRect:inView:animated:

Dismissing the Action Sheet

    – dismissWithClickedButtonIndex:animated:

备注:比对学习下UIAlertView,你会发现这两个类基本类似

这里还有一组常量值
UIActionSheetStyle

Specifies the style of an action sheet.

typedef enum {
   UIActionSheetStyleAutomatic        = -1,
   UIActionSheetStyleDefault          = UIBarStyleDefault,
   UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
   UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
} UIActionSheetStyle;

Constants

UIActionSheetStyleAutomatic

    Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.

UIActionSheetStyleDefault

    The default style.

UIActionSheetStyleBlackTranslucent

    A black translucent style.

UIActionSheetStyleBlackOpaque

    A black opaque style.


协议接口学习

UIActionSheetDelegate协议接口

The UIActionSheetDelegate protocol defines the methods a delegate of a UIActionSheet object should implement. The delegate implements the button actions and any other custom behavior. Some of the methods defined in this protocol are optional.

Responding to Actions

    – actionSheet:clickedButtonAtIndex:

Customizing Behavior

    – willPresentActionSheet:
    – didPresentActionSheet:
    – actionSheet:willDismissWithButtonIndex:
    – actionSheet:didDismissWithButtonIndex:

Canceling

    – actionSheetCancel:

看来,这里和UIAlertViewDelegate接口也类似,学起来也方便多了,good


转载于:https://www.cnblogs.com/GoGoagg/archive/2011/05/26/2057875.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值