zoukankan      html  css  js  c++  java
  • UIActionSheet减少在控制器再写一次代理

    利用 CFRunLoopRun 和 CFRunLoopStop 方法来将 UIActionSheet 改造成同步的调用。

    #import <Foundation/Foundation.h>

    #import <UIKit/UIKit.h>

    @interface SynchronizedUIActionSheet : NSObject

    - (NSInteger)showInView:(UIView *)view;

    @end

    //

    //  SynchronizedUIActionSheet.m

    //  SynchronizedUIActionSheet

    //

    //  Created by Evan on 16/6/29.

    //  Copyright © 2016年 Evan. All rights reserved.

    //

    #import "SynchronizedUIActionSheet.h"

    @interface SynchronizedUIActionSheet ()<UIActionSheetDelegate>

    @property (nonatomic, strong) UIActionSheet *actionSheet;

    @property (nonatomic, assign) NSInteger selectedIndex;

    @end

    @implementation SynchronizedUIActionSheet

    - (NSInteger)showInView:(UIView *)view

    {

          _actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"111" otherButtonTitles:nil, nil];

        [_actionSheet showInView:view];

        CFRunLoopRun();

        return _selectedIndex;

    }

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

        _selectedIndex = buttonIndex;

        _actionSheet = nil;

        CFRunLoopStop(CFRunLoopGetCurrent());

    }

    @end

  • 相关阅读:
    mysql基础
    EM算法总结
    机器学习之PCA(1)
    C语言socket编程<二>
    计算机网络·实验一:
    机器学习之GMM-EM
    C语言socket编程<一>socket之Winsock API
    【翻译】java-TCP-socket网络编程2
    【翻译】java-TCP-socket网络编程1
    【翻译】Java IO 关系总览和整理
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5629767.html
Copyright © 2011-2022 走看看