iOS开发UI篇—直接使用UITableView Controller

iOS开发UI篇—直接使用UITableView Controlleriview

1、通常过程ui

复制代码

//
// YYViewController.h
// UITableView Controller
//
// Created by 孔医己 on 14-6-2.
// Copyright (c) 2014年 itcast. All rights reserved.
//atom

#import <UIKit/UIKit.h>spa

@interface YYViewController : UIViewController代理

@endcode

 
 
复制代码

系统storyboard中默认的控制器为:ViewControllerblog

这样的话若是整个程序界面都只是使用UITableView来搭建,那么通常须要完成如下相对繁琐的步骤:继承

(1)向界面上拖一个UItableview开发

(2)设置数据源animation

(3)设置代理

(4)遵照代理协议

 上述过程相对繁琐,且还须要手动的设置数据源,代理,遵照协议等,容易遗漏,下面推荐直接使用UITableView Controller。
 
2、使用UITableView Controller
  为了简化操做,推出下面的方法。
  即若是在界面上仅仅只是须要用来展现一个UITableView,那么能够让主控制器直接继承于UITableView Controller
复制代码

//
// YYViewController.h
// UITableView Controller
//
// Created by 孔医己 on 14-6-2.
// Copyright (c) 2014年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface YYViewController : UITableViewController

@end

 
  
复制代码
 
 直接让控制器继承UITableView controller,而后在storyboard中把之前的界面删掉,拖一个tableview controller就能够了。
 
注意:须要和主控制器类进行关联。
UITableView Controller里面有个tableview属性,在控制器中经过self.view获取出来的视图就是一个tableview。
即self.view=self.taleview。
且它默认已经把他的协议和数据源都已经实现好了,再也不须要进行连线。
复制代码

// UITableViewController.h
// UIKit
//
// Copyright (c) 2008-2013, Apple Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIViewController.h>
#import <UIKit/UITableView.h>
#import <UIKit/UIKitDefines.h>

// Creates a table view with the correct dimensions and autoresizing, setting the datasource and delegate to self.
// In -viewWillAppear:, it reloads the table's data if it's empty. Otherwise, it deselects all rows (with or without animation) if clearsSelectionOnViewWillAppear is YES.
// In -viewDidAppear:, it flashes the table's scroll indicators.
// Implements -setEditing:animated: to toggle the editing state of the table.

NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

- (id)initWithStyle:(UITableViewStyle)style;

@property(nonatomic,retain) UITableView *tableView;
@property(nonatomic) BOOL clearsSelectionOnViewWillAppear NS_AVAILABLE_IOS(3_2); // defaults to YES. If YES, any selection is cleared in viewWillAppear:

@property (nonatomic,retain) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(6_0);

@end

 
  
复制代码
点击右键,能够发现数据源和代理都已经连好了。
 
(应该把继承自uiviewcontroller的控制器干掉,从新拖一个tableview controller,和主控制器进行连线。)
相关文章
相关标签/搜索