本文主要是介绍IOS学习笔记8—UITableViewController,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UITableViewController是IOS开发中一个比较重要的试图控制器,是集成了UITableView视图的控制器,在实际开发中经常用到,功能非常强大,可定制性也很高,下面从简单的使用和自定义Cell以及事件响应等方面来使用。
1.首先创建一个Single View Project,命名为UITableViewControllerTest。打开ViewController.xib并拖入一个UITableView,选中该视图,并点击Connections inspector,分别将delegate和dataSource连线到File's owner
2.在AppDelegate.h中添加属性
@property (strong, nonatomic) IBOutlet UITabBarController * rootViewController;
并在.m文件中添加合成器
@synthesize rootViewController;
然后在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中添加该TableView为subView
3.在ViewController.h文件中添加协议UITableViewDelegate,UITableViewDataSource,然后在.m文件中实现协议中的方法
#pragma mark -
#pragma mark Table View Data Source Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listDatas count];
}
上面的方法是返回Table中的行数
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * SimpleTableViewIdentifier =@"SimpleTableViewIdentifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableViewIdentifier];
if (cell
这篇关于IOS学习笔记8—UITableViewController的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!