fb_license

技術標籤

@selector (1) 初使化區塊 (1) 物件 (1) 物件導向 (2) 型別 (4) 封裝 (1) 流程控制 (1) 陣列 (3) 推論型別 (2) 實機測試 (1) 蓋索林(gasolin) (1) 模組 (1) 憑證 (1) 轉型 (1) 羅康鴻 (121) 類別 (1) 變數 (5) Accelerometer (1) ActiveRecord (1) Activity (1) AFNetworking (1) alloc (1) Android (3) Animation (1) App (1) App ID (1) APP上傳 (1) ASP.NET (1) AVAudioPlayer (1) block (1) C# (2) class (1) CLLocationManager (1) CLLocationManagerDelegate (1) CMMotionManager (4) Controller (1) delegate (1) DELETE語法 (1) Device Motion資料 (1) Dialog (1) DropDownList (1) dynamic language (2) Facebook SDK (9) FBRequest (5) FBRequestConnection (2) FMDB (1) Gesture Recognizers (6) GROUP BY (2) Gyro (1) HAVING (1) IBAction (1) IBOutlet (1) id (3) inheritance (1) init (1) Insert (1) instance variable (1) Interface Builder (1) iOS (70) iOS idea (7) iOS Introduction (1) Layout (1) Magnetometer (1) Menu (2) Method (2) MKMapView (1) MKPointAnnotation (1) MS SQL (5) Nil (1) NSArray (1) NSDictionary (1) NSError (1) NSFileManager & .plist (1) NSMutableArray (1) NSMutableDictionary (1) NSNotificationCenter (1) NULL (1) object (2) Objective-C (16) Objective-C idea (1) ORDER BY (1) Parameter (1) property (1) protocol (2) Provisioning (1) Proximate Sensor (1) Q and A (2) R類別 (1) Rails (9) RESTful SOA (9) Ruby (8) Scene (1) SEELECT (1) Segue (2) SEL (1) SELECT語法 (1) Shake (1) Simulator (1) SOA (8) SQL (6) SQL Server (5) SQL函數 (1) SQL彙總函數 SQL (1) SQLite (1) Storyboard (1) Style (1) Swift (1) Table (1) target & action (1) Theme (1) Toast (1) TRUNCATE TABLE語法 (1) UIActionSheet (1) UIActionSheetDelegate (1) UIActivityIndicatorView (1) UIAlertView (1) UIBarButtonItem (1) UIButton (1) UICollectionView (1) UICollectionViewDataSource (1) UIControl (9) UIDatePicker (1) UIImage (1) UIImagePickerController (2) UIImagePickerControllerDelegate (2) UIImageView (1) UILabel (1) UILongPressGestureRecognizer (1) UINavigationController (2) UIPanGestureRecognizer (1) UIPinchGestureRecognizer (1) UIProgressView (1) UIResponder (1) UIRotationGestureRecognizer (1) UISegmentedControl (1) UISlider (1) UIStepper (1) UISwipeGestureRecognizer (1) UISwitch (1) UITabBarController (1) UITableView (1) UITableViewDataSource (1) UITapGestureRecognizer (1) UITextField (1) UITextFieldDelegate (1) UITextView (2) UITextViewDelegate (1) UIToolBar (1) UIView (8) UIWebView (1) UPDATE語法 (1) var (2) VB.NET (7) View (4) WHERE子句 (1) XML (1)

2013/06/09

[iOS] UIActionSheet & UIActionSheetDelegate

我是UIActionSheet,我是一個作業選單讓使用者可以選取要進行的作業

但我需要能夠幫我處理作業的人,只要符合UIActionSheetDelegate的protocol協定,都可以接我的工作,幫我處理使用者按下按鈕後的工作


  





第1步:建立一個名為"UIActionSheet_UIActionSheetDelegate"的"Single View Application"專案
 

第2步:加入一個UILabelUIButton,並為UILabel設立名為label的IBOutlet,為UIButton的"Touch Up Inside"事件加上"touch:"方法。以便後續透過UIButton產生UIActionSheet物件,並在使用者選取後,將選取的項目顯示在UILabel上。














第3步:為"ViewController"加上"UIActionSheetDelegate" protocol協定,以擁有處理UIActionSheet工作項目被選取後的處理。

  • 3.1 為"ViewController"加上"UIActionSheetDelegate" protocol協定,於UIViewController後方加上"<UIActionSheetDelegate>"


        @interface ViewController : UIViewController <UIActionSheetDelegate> 
        
        @property (strong, nonatomic) IBOutlet UILabel *label;
        - (IBAction)touch:(id)sender;

        @end 



        - (void)actionSheet:(UIActionSheet *)actionSheet 
        clickedButtonAtIndex:(NSInteger)buttonIndex
        {
            //取得UIActionSheet被點選按鈕上的文字
            NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

            //將文字顯示在UILabel上
            [self.label setText:title]; 
        }




第4步:於"touch:"方法中建立UIActionSheet。並透過"initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:"方法設定按鈕,並指派選取按鈕後處理後續作業的委派物件,當然這個委派物件必須符合"UIActionSheetDelegate"protocol協定。



    - (IBAction)touch:(id)sender {
        //initWithTitle => UIActionSheet的標題文字
        //delegate => 符合UIActionSheetDelegate protocol協助的物件,
        //  用以處理使用者選取按鈕後的工作,
        //  在此以ViewController物件(self)作為委派 
        //cancelButtonTitle => 取消按鈕的文字
        //destructiveButtonTitle => 特殊按鈕的文字,此按鈕會以紅色顯示 
        //otherButtonTitles => 其他按鈕的文字,以","隔開,"nil"結尾 

        UIActionSheet *sheet =
            [[UIActionSheet alloc] initWithTitle:@"要作什麼呢?"
                                        delegate:self cancelButtonTitle:@"不作事!"
                          destructiveButtonTitle:@"緊急任務" 
                               otherButtonTitles:@"玩Game", @"出遊", nil];

        //將UIActionSheet顯示於底層的View上
        [sheet showInView:self.view]; 
    } 



第5步:執行後點選Button,UIActionSheet即會出現,點選按鈕後的按鈕文字字會顯示在UILabel上,以表示選取的按鈕。
  





檔案連結:UIActionSheet_UIActionSheetDelegate.zip