Ipad项目初涉UISplitViewController

新公司,新气象。沉寂了一个月,开始做ipad项目,说起ipad,刚开始心里还有点鼓捣。毕竟之前一直做得是iphone项目,ipad项目没有真正做过,只是在实习的时候做个一个点菜系统。而且还是参与。

既然说到ipad,那么就得说跟iPhone的不同之处。ipad项目从根本上说比iPhone多了两个系统控件,或者说是界面。例如 UISplitViewController和UIPopoverController。

今天暂且说下UISplitViewController,用纯代码展示出这个ipad独有的控件的使用方法。做过iPhone项目都知道,一个UITabbarViewController是包含多个UIviewcontroller的,例如QQ、微信界面,有三个UIVewcontroller构成的框架。这里的UISplitViewController也是类似。我们新建一个UISplitViewController,需要给它声明两个UIViewController,一个表示,左面的列表界面,另一个表示选择列表显示出的详情界面。

下面我们上代码,Appdelegate.h的代码如下:

@class SplitListController;
@class SplitModelController;


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UISplitViewController *splitView;
@property (strong, nonatomic) SplitListController *listContr;
@property (strong, nonatomic) SplitModelController *modelContr;

Appdelegate.m的代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //声明uiwindow
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //设置状态栏字体颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    //列表界面
    self.listContr = [[SplitListController alloc]init];
    UINavigationController *masterNav = [[UINavigationController alloc]initWithRootViewController:_listContr];
    //模型界面
    self.modelContr = [[SplitModelController alloc]init];
    UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:_modelContr];
    //合成splitviewcontroller
    self.splitView = [[UISplitViewController alloc]init];
    [self.splitView setPresentsWithGesture:YES];
    self.splitView.viewControllers = @[masterNav,detailNav];
    self.splitView.delegate = _modelContr;

    self.window.rootViewController = self.splitView;
    [self.window makeKeyAndVisible];

    return YES;
}

列表界面直接继承UITableViewController,他的.m文件代码如下:

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- 
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;

    }

    cell.textLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //给详情内容修改变量(传值)
    AppDelegate * app = (AppDelegate*)[UIApplication sharedApplication].delegate;
    SplitModelController *detille  =  app.modelContr;
    detille.sceneModel = @"你猜!";
    NSLog(@"print :%@",detille);

}

详情界面可以根据自己的需求随意写,只要做好点击列表的cell时切换不同的内容就ok了。
好了,UISplitViewController就暂时讲这些。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值