iOS开发——纯代码界面(UITableViewController)
2016-04-18 17:47
337 查看
创建UITableViewController(表视图控制器)
创建一个类TableViewController继承UITableViewController1、AppDelegate.m中代码如下(记得导入TableViewController不然报错)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; TableViewController *view = [[TableViewController alloc] init]; self.window.rootViewController = view; [self.window makeKeyAndVisible]; return YES; }
2.TableViewController.m中,已下有三个方法必须实现。
(1)- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; (2)- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; (3)- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
TableViewController.m代码如下:
//用来指定表视图的分区个数 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //分区设置为1 return 1; } //用来指定特定分区有多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //设置为20行 return 20; } //配置特定行中的单元格 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { //单元格样式设置为UITableViewCellStyleDefault cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } //设置单元格中的imageView cell.imageView.image = [UIImage imageNamed:@"Totoro副本"]; //设置单元格中的textLable cell.textLabel.text = @"龙猫"; return cell; } //设置单元格的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPat { //这里设置成150 return 150; }
3.运行程序,结果如下:
相关文章推荐
- 使用SoapUI做webservice的模拟系统实例
- list、listkey、listValue属性
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 南京理工大学第八届程序设计大赛(校外镜像) sequence(dp+二分)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- ZJU/ZOJ Deque and Balls 3929 计数:小的情况对总情况的贡献。 小心mod运算陷阱
- Uiautomator ------通过控件ID来查找进行测试
- Ant:build.xml 结构
- Web开发之一:Web UI技术综述
- easyUI实现动态增加表头
- 【Arduino官方教程第一辑】示例程序 1-6 制作一个简易电压表
- django book querysets
- Request 接收参数乱码原理解析
- web.xml报错<async-supported>true</async-supported>
- 别着急学软件!先掌握科学有效的UI设计自学姿势(超全面)
- BestCoder Round #80 Sequence(HDU5667) 费马小丁里和矩阵乘法的应用
- 更新UI的方法
- 深入分析Parquet列式存储格式
- PostgreSQL 序列(SEQUENCE)
- [POJ3061]Subsequence(二分,前缀和)