<三>UITableView使用
来源:互联网 发布:linux wait源码分析 编辑:程序博客网 时间:2024/06/05 13:23
一 、设置UITableView的dataSource、delegate
二 、UITableView使用
@property (nonatomic,assign)id <UITableViewDataSource> dataSource;
2. 设置数据源
self.tableView.dataSource = self;
或者 在StoryBoard 连线到控制器
3. 实现数据源 3个方法
//一共有多少组数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
//每一组有多少行数据
-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section;
// 每一行显示什么内容
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath;
2> 用UITableView方法
1. 要遵守 UITableViewDelegate
2. 设置代理
self.tableView.delegate =self;
或者 在StoryBoard 连线到控制器
/**
* 每一行的高度不一致的时候使用这个方法来设置行高
*/
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==0)return 100;
return60;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<三> UITableView 常见属性
// 分割线
self.tableView.separatorColor = [UIColorcolorWithRed:255/255.0green:255/255.0blue:0alpha:255/255.0];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//表格的头部控件(直接显示表格的最顶部)
self.tableView.tableHeaderView = [UIButtonbuttonWithType:UIButtonTypeContactAdd];
self.tableView.tableFooterView = [[UISwitchalloc] init];
<四> Cell 常见属性
// 取出模型
Person *pserson = self.persons[indexPath.row];
// 设置cell的数据
// 文字
cell.textLabel.text = person.name;
// 明细文字
cell.detailTextLabel.text = person.intro;
// 左边图标
cell.imageView.image = [UIImageimageNamed:person.icon];
// 设置cell右边指示器的类型
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
// cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
// cell.accessoryView = [[UISwitch alloc] init];
// 设置背景(背景view不用设置尺寸, backgroundView的优先级 > backgroundColor)
UIImageView *bgView = [[UIImageViewalloc] init];
bgView.image = [UIImageimageNamed:@"buttondelete"];
// bgView.backgroundColor = [UIColor redColor];
cell.backgroundView = bgView;
UIView *selectedbgView = [[UIViewalloc] init];
selectedbgView.backgroundColor = [UIColorgreenColor];
cell.selectedBackgroundView = selectedbgView;
- <三>UITableView使用
- UITableView<三>
- UITableView的基本使用三(自定义Cell)
- UITableView使用
- UITableView使用
- UITableView使用
- UITableView使用
- UITableView使用
- UITableView(三)--- UITableViewDataSource
- swift UITableView(三)
- 三、IOS UITableView详解
- IOS UITableView (三)
- UITableView(三)----性能优化
- UITableView之(三):UITableViewCell
- UITableView delegate的使用
- UITableView 使用心得
- UITableView 使用总结
- UITableView的简单使用
- 算法之排序小结2---归并排序(Java)
- springMVC整合velocity框架
- 《万万没想到》第二季结束了
- 三张图教你生成一个Android jar 库。
- eclipse android 程序 转化为android studio
- <三>UITableView使用
- 【Java.JMS】【springframework.jms】
- php-getenv
- sql查询表大小行数以及使用空间
- C++打印程序自身
- 短信拦截木马背后的黑色产业
- 哈夫曼树的构建
- SSH bash紧急安全补丁!重要!
- 求三角形的面积