iOS 启动页实现方案

启动页的定位

1.由于每次打开都能看到,因此启动页常用于广告位,为产品带来盈利。
2.用来判断是跳转主页面还是登陆界面。
3.用来缓冲app的加载时间。

实现思路

在didFinishLaunchingWithOptions里面创建两个Window,一个是主Window,一个是启动页Window,启动页用来判断是跳转主页面还是登陆界面。
如果是登录状态,那么在规定时间内销毁启动页window,展示主Window。
如果不是登录状态,那么就从引导页跳转登录界面,登录成功后在销毁启动页Window。

优点

1.降低耦合性。
2.不用修改框架的结构。
3.根控制器不变。

实现代码

#import "AppDelegate.h"
#import "ViewController.h"
#import "StyleViewController.h"

@interface AppDelegate ()

/**  */
@property (nonatomic, strong) UIWindow *styleWindow;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 创建主window
    [self styleOne];
    
    // 创建引导页window
    [self styleTwo];
  
    return YES;
}


/**
 主window
 */
- (void)styleOne{
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
}


/**
 引导页window
 */
- (void)styleTwo{
    
    // 创建第二个window,遮挡住第一个window
    // 引导页的操作到StyleViewController控制器里面做
    self.styleWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.styleWindow.backgroundColor = [UIColor whiteColor];
    self.styleWindow.rootViewController = [[StyleViewController alloc] init];
    [self.styleWindow makeKeyAndVisible];

    // 定时销毁
    [self performSelector:@selector(cancelStyleWindow) withObject:nil afterDelay:5];
}


/**
 销毁引导页Window
 */
- (void)cancelStyleWindow{
    
    [self.styleWindow resignKeyWindow];
    self.styleWindow = nil;
}


@end
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的 iOS UITableView 的代码实现示例: 1. 首先,在你的视图控制器中添加 UITableView 属性: ``` @interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end ``` 2. 在 viewDidLoad 方法中初始化 UITableView: ``` - (void)viewDidLoad { [super viewDidLoad]; // 初始化 UITableView self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; [self.view addSubview:self.tableView]; } ``` 3. 实现 UITableViewDataSource 协议中的方法: ``` // 返回 UITableView 中的 section 数量 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // 返回 UITableView 中某个 section 中的 row 数量 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } // 返回 UITableView 中某个 indexPath 的 cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"MyCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"Cell %ld", (long)indexPath.row]; return cell; } ``` 4. 实现 UITableViewDelegate 协议中的方法,比如设置 cell 的高度: ``` - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 44.0f; } ``` 以上就是一个简单的 UITableView 的代码实现示例。需要注意的是,UITableView 必须指定 delegate 和 dataSource,而且需要实现 UITableViewDataSource 和 UITableViewDelegate 协议中的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值