UITableView(一)
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSArray *_dataList;
@property (nonatomic, retain) UITableView *_myTableView;
@end
//
// ViewController.m
// ios13
//
// Created by fredric on 16/4/14.
// Copyright © 2016年 fredric. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSArray *list = [NSArray arrayWithObjects:@"条目1",@"条目2", nil];
self._dataList = list; UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self; self._myTableView = tableView; [self.view addSubview:self._myTableView]; } #pragma mark - Table view data source
/*-
* 创建某个section及某个row中UITableViewCell的定义
* NSIndexPath 包含sectoin、row两个方法获取对应的section和row
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //通过Identifier在tableView的缓冲池中寻找cell对象
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if(cell == nil){
//若缓冲池中没有则创建这个对象
// UITableViewCell 包含四种显示方式
// UITableViewCellStyleDefault 为默认的左对齐格式
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
} cell.textLabel.text = [self._dataList objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = @"详细信息"; return cell;
} //一共有多少个分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} //分区中有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self._dataList count];
} #pragma mark - Table view delegate
//选择UITableView的某一行
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *showSelection;
showSelection = [[UIAlertView alloc]
initWithTitle: @"已经选择了"
message: [NSString stringWithFormat: @"%d", [indexPath row]]
delegate: nil
cancelButtonTitle: @"Ok"
otherButtonTitles: nil];
[showSelection show];
} @end
UITableView(一)的更多相关文章
- iOS UITableView 与 UITableViewController
很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...
- UITableView(二)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- iOS: 在UIViewController 中添加Static UITableView
如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...
- iOS 编辑UITableView(根据iOS编程编写)
上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为 e ...
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题
UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...
- UITableview delegate dataSource调用探究
UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...
- UITableView点击每个Cell,Cell的子内容的收放
关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...
- 使用UITableView的分组样式
分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...
随机推荐
- ExtJS基础知识总结:自定义日历和ComboBox控件(二)
概述 1.ExtJS 5不支持日期选择框中只选择年月,为了满足ExtJs5可以实现选择年月的功能,查询网上资料,整理出来了相应的处理方式,最终实现的效果如下图: 2.ExtJS 控件丰富,如果需要实现 ...
- Datazen介绍
Datazen是移动端全平台的图表解决方案,基于HTML5的应用,实现了全平台的整合.此篇主要对其功能进行大体介绍. 这个平台最近刚被微软收购,相信微软看重的是其HTML5在全移动端平台的实现.Dat ...
- [转]IIS6.0迁移至IIS7.0
原文地址:http://www.splaybow.com/post/iis-6.0-7.0.html 公司的项目需要迁移到IIS7的目标机器中 在此做记录 原来server 2003系统 迁到2008 ...
- 控制台查看原生sql
情况:当tomcat运行时,项目运行过程中,控制台没有打印出原生sql语句: 解决办法如下: 在 META-INF 文件夹下,查找 persistence.xml 这个文件(这里注意可能一个项目不止 ...
- Swift 基本常量和变量,基本数据类型
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #4dbf56 } p.p2 { margin: 0.0px 0. ...
- Nginx - Windows下作为服务启动
Nginx官方没有提供作为服务启动nginx的方案.以服务启动nginx依赖于winsw,当前最新版是1.19. 参考:https://segmentfault.com/a/1190000006807 ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- 【转】Wireshark基本用法
原地址:http://blog.jobbole.com/70907/ 按照国际惯例,从最基本的说起. 抓取报文: 下载和安装好Wireshark之后,启动Wireshark并且在接口列表中选择接口名, ...
- C++ 代码优化
1.类中所有的属性全部设置为private 然后在需要在外部调用的属性,每个都自己写Get方法返回,或者用Set方法设置 2.类成员变量采用m_前缀,代表类成员 3.采用单例模式 //设置类名为CCo ...
- LNMP虚拟机开发环境配置--vagrant+virtualbox+ubuntu14.04
工作一直用的是别人打包好的虚拟机开发环境,感觉确实很酷.所以准备自己配个开发环境,为之后自己开发一些有趣的东西做准备. ok,开始~~~ 一.安装软件 vagrant和virtualbox 此处需注意 ...