iOS-メッセージ弾枠Alert
1870 ワード
説明
UIAlertViewはiOS 9.0で廃棄されているので、UIAlertControllerで代用する必要があります.
ヘッダファイル
ソースファイル
UIAlertViewはiOS 9.0で廃棄されているので、UIAlertControllerで代用する必要があります.
ヘッダファイル
#import
@interface ViewController : UIViewController{
//UIAlertView* v;
//
UIAlertController* _ac;
}
//
@property(nonatomic, retain)UIAlertController * ac;
@end
ソースファイル
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize ac = _ac;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100, 100, 100);
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@" " forState:UIControlStateNormal];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void) onClick:(UIButton*) btn{
NSLog(@" %@",btn.currentTitle);
[self alert];
}
-(void) alert{
//UIAlertView iOS9 , UIAlertController
// UIAlertController, 、 、
_ac = [UIAlertController alertControllerWithTitle:@"title" message:@"msg" preferredStyle:UIAlertControllerStyleAlert];
//
NSArray* arr = @[@"a",@"b",@"c",@"d",@"e"];
//
NSInteger count = [arr count];
// , UIAlertAction*, : 、
// UIAlertActon
for(int i=0; i