您的位置:首页 > 产品设计 > UI/UE

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];

选中某一行

NSIndexPath *ip=[NSIndexPath
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];//选中后的反显颜色即刻消失
。。。。。。
}
待续。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: