成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iOS開發:創建獨立的警告視圖

移動開發 iOS
我們向用戶提供了選項,并且需要這些選項,可以通過實現協議里的方法。我們通過以下兩個方法判斷選擇:硬編碼的方式對按鈕的索引做比較,或用switch語句;通過-buttonTitleAtIndex方法,比較字符串。

UIAlertView 的基本用法就不再說了,如果我們向用戶提供了選項,并且需要這些選項,可以通過實現協議里的方法。我們通過以下兩個方法判斷選擇:

1,硬編碼的方式對按鈕的索引做比較,或用switch語句。

2,通過-buttonTitleAtIndex方法,比較字符串。

如果警告視圖較多,那就不只是判斷是那個按鈕被按下,而是那個警告視圖的那個按鈕了。

我們使用Block能讓這個過程更加漂亮。

XYAlertView.h:

  1. #import <UIKit/UIKit.h>   
  2.     typedef void(^XYAlertBlock)(void); 
  3.     @interface XYAlertView : UIAlertView<UIAlertViewDelegate>{ 
  4.     } 
  5.     + (void)showWithTitle:(NSString *)title 
  6.                   message:(NSString *)message 
  7.               buttonTitle:(NSString *)buttonTitle; 
  8.     + (void)showWithTitle:(NSString *)title 
  9.                   message:(NSString *)message 
  10.               cancelTitle:(NSString *)cancelTitle 
  11.               cancelBlock:(XYAlertBlock)cancelBlock 
  12.                otherTitle:(NSString *)otherTitle 
  13.                otherBlock:(XYAlertBlock)otherBlock; 
  14.     @end 

XYAlertView.m:

  1. #import "XYAlertView.h"   
  2.     @interface XYAlertView () 
  3.     @property (nonatomic, copy) XYAlertBlock cancelBlock; 
  4.     @property (nonatomic, copy) XYAlertBlock otherBlock; 
  5.     @property (nonatomic, copy) NSString *cancelButtonTitle; 
  6.     @property (nonatomic, copy) NSString *otherButtonTitle; 
  7.     - (id)initWithTitle:(NSString *)title 
  8.                 message:(NSString *)message 
  9.             cancelTitle:(NSString *)cancelTitle 
  10.              ancelBlock:(XYAlertBlock)cancelBolck 
  11.              otherTitle:(NSString *)otherTitle 
  12.              otherBlock:(XYAlertBlock)otherBlock; 
  13.     @implementation XYAlertView 
  14.     @synthesize cancelBlock = _cancelBlock; 
  15.     @synthesize otherBlock = _otherBlock; 
  16.     @synthesize cancelButtonTitle = _cancelButtonTitle; 
  17.     @synthesize otherButtonTitle = _otherButtonTitle; 
  18.     + (void)showWithTitle:(NSString *)title message:(NSString *)message buttonTitle:(NSString *)buttonTitle{ 
  19.         [self showWithTitle:title message:message cancelTitle:buttonTitle cancelBlock:nil otherTitle:nil otherBlock:nil]; 
  20.     } 
  21.     + (void)showWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle cancelBlock:(XYAlertBlock)cancelBlock otherTitle:(NSString *)otherTitle otherBlock:(XYAlertBlock)otherBlock{ 
  22.         [[[self alloc] initWithTitle:title message:message cancelTitle:cancelTitle ancelBlock:cancelBlock otherTitle:otherTitle otherBlock:otherBlock] show]; 
  23.     } 
  24.     - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle ancelBlock:(XYAlertBlock)cancelBolck otherTitle:(NSString *)otherTitle otherBlock:(XYAlertBlock)otherBlock{ 
  25.         if ((self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:otherTitle, nil])) { 
  26.             if (cancelBolck == nil && otherBlock == nil) { 
  27.                 self.delegate = nil; 
  28.             } 
  29.             self.cancelButtonTitle = cancelTitle; 
  30.             self.otherButtonTitle = otherTitle; 
  31.             self.cancelBlock = cancelBolck; 
  32.             self.otherBlock = otherBlock; 
  33.         } 
  34.         return self; 
  35.     } 
  36.     #pragma mark - 
  37.     #pragma mark UIAlertViewDelegate 
  38.     - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
  39.         NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; 
  40.         if ([buttonTitle isEqualToString:self.cancelButtonTitle]) { 
  41.             if (self.cancelBlock) { 
  42.                 self.cancelBlock(); 
  43.             } 
  44.         }else if ([buttonTitle isEqualToString:self.otherButtonTitle]){ 
  45.             if (self.otherBlock) { 
  46.                 self.otherBlock(); 
  47.             } 
  48.         } 
  49.     } 
  50.     @end 

 

源代碼下載:http://down.51cto.com/data/835995

責任編輯:閆佳明 來源: oschina
相關推薦

2013-06-14 13:50:28

iOS開發移動開發警告視圖

2013-03-29 11:06:24

iOS開發滾動視圖UIScrol

2011-08-09 15:17:07

iOS開發

2014-09-02 10:55:25

iOS開發視圖切換

2010-11-16 10:42:45

Oracle創建視圖

2012-05-10 09:08:07

iOS獨立開發者

2010-11-11 17:20:51

SQL Server創

2011-04-19 10:38:53

Xcode 4MacRubyiOS

2014-03-14 13:36:19

獨立游戲經驗

2015-08-05 10:43:40

開發者開發工具

2015-08-05 14:25:26

開發者開發工具

2013-07-21 18:09:21

iOS開發ASIHttpRequ創建和執行reques

2009-04-07 10:45:43

Oracle視圖創建

2018-07-25 14:01:47

iOS開發蘋果

2011-01-28 15:20:53

開發者MGF

2012-03-26 09:35:00

手機游戲開發者

2011-07-08 14:51:34

iPhone 視圖

2012-05-02 23:04:38

iOS

2012-05-13 12:43:50

iOS

2011-04-25 16:56:34

Greedy Bank游戲開發獨立開發者
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久久999国产精品 中文字幕在线精品 | 毛片毛片毛片毛片 | 日本理论片好看理论片 | 色视频网站在线观看 | 国产精品一区二区精品 | 国产精品久久久久久久久免费 | 久草新在线 | 日韩欧美三级在线 | 久久久精| 亚洲欧美在线免费观看 | 久久国产精品免费一区二区三区 | 日韩在线播放网址 | 亚洲色视频 | 99国产精品一区二区三区 | 日本国产一区二区 | 亚洲精品在线看 | 精品一级 | 国产精品成人免费 | 中文字幕精品一区 | 天堂素人约啪 | 亚洲黄色片免费观看 | 视频一区在线观看 | 国产91在线 | 中日 | 精品九九 | 日韩视频免费看 | 国产成人精品一区二区三区四区 | 91热在线| 99精品欧美一区二区三区 | 国产专区在线 | 久久久www成人免费精品 | 337p日韩| 欧美一级黄视频 | 四虎影院在线观看av | 国产精品免费一区二区三区四区 | 欧美一区二区久久 | 91看片| 国产精品国产三级国产播12软件 | 99视频免费看 | 伊人网99 | 亚洲精品国产一区 | 在线观看亚洲欧美 |