153 lines
6.1 KiB
Objective-C
Executable File

//
// HttpManager.m
// myhome
//
// Created by hkh on 16/11/6.
//
#import "Msg.h"
#import "Pub.h"
//#import "HKHTextField.h"
#import "BaseViewController.h"
#import "OpenPwd.h"
#import "UI.h"
@interface Msg (){
}
@end
@implementation Msg{
}
+ (void)alert:(NSString *)msg{
@try
{
if([@"MainTabBar" isEqualToString:NSStringFromClass([[Pub getApp].window.rootViewController class])]){
UITabBarController *tab = (UITabBarController *)[Pub getApp].window.rootViewController;
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
BaseViewController *v = (BaseViewController *)nav.viewControllers[nav.viewControllers.count-1];
[v alert:msg];
}
} @catch (NSException * e) {
NSLog(@"%@",e);
}
}
+ (void)Alert:(UIViewController *)page Msg:(NSString *)msg{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"无需处理");
}];
[alertController addAction:okAction];
[page presentViewController:alertController animated:YES completion:nil];
}
+ (UIAlertController *)Waiting:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(void)) handler {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
if(handler)handler();
}];
[alertController addAction:cancelAction];
[page presentViewController:alertController animated:YES completion:nil];
return alertController;
}
+ (void)MessageBox:(UIViewController *)page Msg:(NSString *)msg SelectedHandler:(void (^)(int index)) handler {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提⽰" message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
handler(1);
NSLog(@"确定");
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[page presentViewController:alertController animated:YES completion:nil];
}
+ (UIAlertController *)OpendoorByPwd:(UIViewController *)page SelectedHandler:(void (^)(int index)) handler {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请输入开门密码" message:@"\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
handler(1);
NSLog(@"确定");
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
OpenPwd *open = [[OpenPwd alloc] init];
open.parent = page;
[alertController addChildViewController:open];
[alertController.view addSubview:open.view];
open.view.frame = CGRectMake(0, 50, 270, 50);
[open setUI];
[page presentViewController:alertController animated:YES completion:^{
[open focusTextField];
}];
//[alertController dismissViewControllerAnimated:YES completion:nil];
return alertController;
}
+ (void)Select:(UIViewController *)page SourceView:(UIView *)view Title:(NSString *)title Options:(NSArray *)arr SelectedHandler:(void (^)(int index)) handler {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
NSLog(@"Select1");
actionSheet.popoverPresentationController.sourceView = page.view;
NSLog(@"Select2");
@try
{
actionSheet.popoverPresentationController.sourceRect = CGRectMake(view.frame.origin.x + (view.frame.size.width-200)/2, view.frame.origin.y + 50, 200, 100);
} @catch (NSException * e) {
actionSheet.popoverPresentationController.sourceRect = CGRectMake([UI getScreenWidth] - 200, 0, 200, 100);
}
//actionSheet.popoverPresentationController.sourceRect = page.view.frame;
NSLog(@"Select3");
for (int i=0;i<arr.count;i++){
NSLog(@"Select:%@", NSStringFromClass([arr[i] class]));
if([@"__NSDictionaryM" isEqualToString:NSStringFromClass([arr[i] class])]){
UIAlertAction *action1 = [UIAlertAction actionWithTitle:[arr[i] valueForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
handler(i);
}];
[actionSheet addAction:action1];
}
else if([@"CBPeripheral" isEqualToString:NSStringFromClass([arr[i] class])]){
UIAlertAction *action1 = [UIAlertAction actionWithTitle:[arr[i] valueForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
handler(i);
}];
[actionSheet addAction:action1];
}
else{
UIAlertAction *action1 = [UIAlertAction actionWithTitle:arr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
handler(i);
}];
[actionSheet addAction:action1];
}
}
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
handler(-1);
}];
//把action添加到actionSheet里
[actionSheet addAction:cancel];
//相当于之前的[actionSheet show];
[page presentViewController:actionSheet animated:YES completion:nil];
}
@end