IOS疯狂基础之UITableView
2013-03-18 15:19
316 查看
滚动到指定行
NSIndexPath *lastRow
= [NSIndexPath indexPathForRow:([self.loadedImages count]
- 1) inSection:0];
[self.imagesTableView scrollToRowAtIndexPath:lastRow
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
刷新某一行
NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:1 inSection:0];
NSArray *indexArray=[NSArray arrayWithObject:indexPath_1];
[regTableView reloadRowsAtIndexPaths:indexArray
withRowAnimation:UITableViewRowAnimationNone];
indexPathForRow:0
inSection:0];
[self.table
selectRowAtIndexPath:ip animated:YES
scrollPosition:UITableViewScrollPositionBottom];
UITableView的常用使用步骤和注意点
1. h文件实现必要协议
<UITableViewDataSource,UITableViewDelegate>
2. //代码创建载入
UITableView *
dataTabel = [[UITableViewalloc]initWithFrame:CGRectMake(10,45,300,self.view.bounds.size.height-65)style:UITableViewStylePlain];
[dataTabel setDelegate:self];
[dataTabel setDataSource:self];
//dataTabel.allowsSelection = NO;不让选事件都不触发了
[self.view
addSubview:dataTabel];
[dataTabel reloadData];
3.实现代理方法
#pragma TabelView
//指定有多少个分区(Section),默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//每个section显示的标题
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{
return @"";
}
//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
return [nameArrcount];
}
//划动cell是否出现del按钮
- (BOOL)tableView:(UITableView *)tableViewcanEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
//绘制Cell这个是主要的
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier =@"SimpleTableIdentifier";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: SimpleTableIdentifier] ;
}
NSArray *subviews = [[NSArrayalloc]initWithArray:cell.contentView.subviews];//这个代码主要是防止点击时出现重复数据,这个是cell的重用机制
for (UIView *subviewin subviews) {
[subview removeFromSuperview];
}
。。。。。。
return cell;
}
//改变行的高度
- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 90;
}
//选中Cell响应事件
- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPathanimated:YES];//选中后的反显颜色即刻消失
。。。。。。
}
待续。。。。
NSIndexPath *lastRow
= [NSIndexPath indexPathForRow:([self.loadedImages count]
- 1) inSection:0];
[self.imagesTableView scrollToRowAtIndexPath:lastRow
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
刷新某一行
NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:1 inSection:0];
NSArray *indexArray=[NSArray arrayWithObject:indexPath_1];
[regTableView reloadRowsAtIndexPaths:indexArray
withRowAnimation:UITableViewRowAnimationNone];
选中某一行
NSIndexPath *ip=[NSIndexPathindexPathForRow:0
inSection:0];
[self.table
selectRowAtIndexPath:ip animated:YES
scrollPosition:UITableViewScrollPositionBottom];
UITableView的常用使用步骤和注意点
1. h文件实现必要协议
<UITableViewDataSource,UITableViewDelegate>
2. //代码创建载入
UITableView *
dataTabel = [[UITableViewalloc]initWithFrame:CGRectMake(10,45,300,self.view.bounds.size.height-65)style:UITableViewStylePlain];
[dataTabel setDelegate:self];
[dataTabel setDataSource:self];
//dataTabel.allowsSelection = NO;不让选事件都不触发了
[self.view
addSubview:dataTabel];
[dataTabel reloadData];
3.实现代理方法
#pragma TabelView
//指定有多少个分区(Section),默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//每个section显示的标题
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{
return @"";
}
//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
return [nameArrcount];
}
//划动cell是否出现del按钮
- (BOOL)tableView:(UITableView *)tableViewcanEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
//绘制Cell这个是主要的
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier =@"SimpleTableIdentifier";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: SimpleTableIdentifier] ;
}
NSArray *subviews = [[NSArrayalloc]initWithArray:cell.contentView.subviews];//这个代码主要是防止点击时出现重复数据,这个是cell的重用机制
for (UIView *subviewin subviews) {
[subview removeFromSuperview];
}
。。。。。。
return cell;
}
//改变行的高度
- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 90;
}
//选中Cell响应事件
- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPathanimated:YES];//选中后的反显颜色即刻消失
。。。。。。
}
待续。。。。
相关文章推荐
- iOS基础-高级视图-UITableView--实例:QQ聊天
- IOS开发UI基础UITableView的属性
- iOS开发UI基础—28使用UItableview完成一个简单的QQ好友列表(二)
- iOS UITableView一些基础知识
- IOS UITableView 基础应用
- iOS基础 - UITableView的数据源(dataSource)和代理(delegate)
- iOS基础-高级视图-UITableView--静态单元格
- iOS疯狂详解之UITableView的全选和多选功能
- iOS基础--UITableView,UITableViewController
- [iOS基础控件 - 6.2] LOL英雄列表 UITableView单项显示
- ios开发基础1---UITableView中cell重用导致内容出错
- iOS 编程中 UI 部分UITableView基础知识
- iOS基础-高级视图-UITableView--实例:app管理
- iOS开发UI基础—30在UItableview中实现加载更多功能
- iOS开发UI基础—31在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
- iOS基础:UITableView简单使用
- UITableView的基础知识——IOS
- iOS开发UI基础—32直接使用UITableView Controller
- 【iOS基础控件 6 】 汽车品牌展示 Model嵌套/KVC/TableView索引 <UITableView>
- IOS系列——UItableview的基础使用