程序员

界面跳转及弹窗功能

2015-12-03  本文已影响629人  ThEAll

import "AppDelegate.h"

import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


import "ViewController.h"

import "RegisterViewController.h"

@interface ViewController ()
@end

@implementation ViewController

}

-(void)jumpRegisterVC:(UIButton*)sender{
// 初始化注册视图控制器
RegisterViewController *registerVC = [[RegisterViewController alloc]init];
// 模态出注册的视图控制器
[self presentViewController:registerVC animated:YES completion:^{
NSLog(@"注册的视图控制器以显示");
}];

}

// 实现 sheet按钮的点击事件
-(void)sheetBtnAction:(UIButton*)sender{
// 初始化sheet
UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"sheet" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其余", nil];
// 显示sheet
[sheet showInView:self.view];
}

// 实现 新型弹出框 按钮的点击事件
-(void)newBtnAction:(UIButton*)sender{
// 警示框控制器 这是iOS8之后出来的新类,用于替换原来的UIAlertView 和UIActionSheet
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"收红包" preferredStyle:UIAlertControllerStyleAlert];
// 为警示框添加点击按钮
// title: 警示框按钮标题
// style: 按钮的样式(枚举值)
// handler: 点击该按钮就会执行的语句(block)
// 取消按钮
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"我点击了取消按钮");
}];
// 确定按钮
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"我点击了确定按钮");
}];

//  将创建好的cancelAction添加到警示框视图控制器上
[alertController addAction:cancelAction];
[alertController addAction:sureAction];

//  视图控制器之间切换的一种样式,称之为模态

// <将被废弃的>[self presentModalViewController:alertController animated:YES];

//  上面那种模态方式为iOS5.0之前的代码,下面为iOS5.0之后的模态新方法

//  controller:将要模态出来的视图控制器
//  animated:模态推出视图控制器的过程时候需要动画
//  completion“模态推出视图控制器之后将要执行的操作(block)
[self presentViewController:alertController animated:YES completion:^{
    NSLog(@"我是警示框视图控制器,我已经显示");
}];

}

// 实现按钮的点击事件
-(void)btnAction:(UIButton*)sender{
// 警示框
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"标题" message:@"内容" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",@"确定2", nil];
// 显示alertView
[alertView show];
}

pragma mark ---alertView 的代理方法

//跟踪点击的是alertView的哪个按钮
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"buttonIndex -- %ld",buttonIndex);
}

@end

import "RegisterViewController.h"

@interface RegisterViewController ()

@end

@implementation RegisterViewController

-(void)backAction:(UIButton*)sender{
// 只有当前的视图控制器是模态出来的时候,才可以使用此方法取消或者返回上一级的视图控制器
// 它和模态是一一对应的
// 消失的时候,是将当前视图从父视图上移除
[self dismissViewControllerAnimated:YES completion:^{
}];
}

上一篇 下一篇

猜你喜欢

热点阅读