国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

IOS開發:提示框的正_確實現方式

2019-11-02 14:19:19
字體:
來源:轉載
供稿:網友

 IOS開發:提示框的正確實現方式 電腦高手

  在從iOS8到iOS9的升級過程中,彈出提示框的方式有了很大的改變,在Xcode7 ,iOS9.0的SDK中,已經明確提示不再推薦使用UIAlertView,而只能使用UIAlertController,我們通過代碼來演示一下。

  我通過點擊一個按鈕,然后彈出提示框,代碼示例如下:

  [objc] view plaincopyprint?

  #import "ViewController.h"

  @interface ViewController ()

  @property(strong,nonatomic) UIButton *button;

  @end

  @implementation ViewController

  - (void)viewDidLoad {

  [super viewDidLoad];

  self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [[UIScreen mainScreen] bounds].size.width, 20)];

  [self.button setTitle:@"跳轉" forState:UIControlStateNormal];

  [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

  [self.view addSubview:self.button];

  [self.button addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];

  }

  -(void)clickMe:(id)sender{

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"按鈕被點擊了" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil nil];

  [alert show];

  }

  @end

  編寫上述代碼時,會有下列的警告提示:

  “‘UIAlertView’ is deprecated:first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredSty

巴巴影院[www.aikan.tv/special/babayingyuan/]
le of UIAlertControllerStyleAlert instead”.

  說明UIAlertView首先在iOS9中被棄用(不推薦)使用。讓我們去用UIAlertController。但是運行程序,發現代碼還是可以成功運行,不會出現crash。

  但是在實際的工程開發中,我們有這樣一個“潛規則”:要把每一個警告(warning)當做錯誤(error)。所以為了順應蘋果的潮流,我們來解決這個warning,使用UIAlertController來解決這個問題。代碼如下:

  [objc] view plaincopyprint?

  #import "ViewController.h"

  @interface ViewController ()

  @property(strong,nonatomic) UIButton *button;

  @end

  @implementation ViewController

  - (void)viewDidLoad {

  [super viewDidLoad];

  self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [[UIScreen mainScreen] bounds].size.width, 20)];

  [self.button setTitle:@"跳轉" forState:UIControlStateNormal];

  [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

  [self.view addSubview:self.button];

  [self.button addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];

  }

  -(void)clickMe:(id)sender{

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 明星| 永吉县| 新民市| 耒阳市| 新绛县| 新邵县| 南溪县| 凤冈县| 施秉县| 外汇| 夏河县| 望谟县| 泰州市| 台中市| 平顶山市| 诸城市| 墨江| 定边县| 五大连池市| 康定县| 鄂托克旗| 澄迈县| 灯塔市| 比如县| 伊通| 正宁县| 金平| 洱源县| 错那县| 南漳县| 泰顺县| 云梦县| 濮阳市| 含山县| 台湾省| 伊通| 嘉义县| 镇宁| 鄯善县| 平利县| 花莲市|