presentViewController

模态窗口只是视图控制器显示的一种方式(在iOS中并没有专门的模态窗口类),模态窗口不依赖于控制器容器(例如前两种视图切换一个依赖于UITabBarController,另一个依赖于UINavigationController),通常用于显示独立的内容,在模态窗口显示的时其他视图的内容无法进行操作。

模态窗口使用起来比较容易,一般的视图控制器只要调用- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);方法那么参数中的视图控制器就会以模态窗口的形式展现,同时调用- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion NS_AVAILABLE_IOS(5_0);方法就会关闭模态窗口。



#import "KCLoginViewController.h”
@interface KCLoginViewController ()
@end
@implementation KCLoginViewController
-(void)viewDidLoad {
    [super viewDidLoad];
    [self addLoginForm];
}
-(void)addLoginForm{
    
  //登录按钮
    UIButton *btnLogin=[UIButton buttonWithType:UIButtonTypeSystem];
    btnLogin.frame=CGRectMake(120, 270, 80, 30);
    [btnLogin setTitle:@"登录" forState:UIControlStateNormal];
    [self.view addSubview:btnLogin];
//取消登录按钮
    UIButton *btnCancel=[UIButton buttonWithType:UIButtonTypeSystem];
    btnCancel.frame=CGRectMake(170, 270, 80, 30);
    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:btnCancel];
    [btnCancel addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
}
-(void)cancel
{
    [self dismissViewControllerAnimated:YES completion:nil];//点击取消
}


@end

1111111111111111111111


#import "KCMainViewController.h"
#import "KCLoginViewController.h”
@interface KCMainViewController ()<KCMainDelegate,UIActionSheetDelegate>
{
    UILabel *_loginInfo;
    UIBarButtonItem *_loginButton;
    BOOL _isLogin;
}
@end
@implementation KCMainViewController
- (void)viewDidLoad {
    [super viewDidLoad];
      [self addNavigationBar];
    [self addLoginInfo];
}
-(void)addLoginInfo
{
    _loginInfo = [[UILabel alloc]initWithFrame:CGRectMake(0, 100,320 ,30)];
    _loginInfo.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_loginInfo];
}
#pragma mark 添加到导航栏
-(void)addNavigationBar
{
    UINavigationBar *navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44+20)];
    [self.view addSubview:navigationBar];
    UINavigationItem *navigationItem = [[UINavigationItem alloc]initWithTitle:@"Web Chat"];
//左侧添加登录按钮
    _loginButton=[[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStyleDone target:self action:@selector(login)];
navigationItem.leftBarButtonItem=_loginButton;
 [navigationBar pushNavigationItem:navigationItem animated:NO];
}
宋鸿业  21:21:18
-(void)login
{
    
     KCLoginViewController *loginController = [[KCLoginViewController alloc]init];
        loginController.delegate = self;
        [self presentViewController:loginController animated:YES completion:nil];
}
@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值