滚动到指定行
NSIndexPath *lastRow = [NSIndexPath indexPathForRow:([self.loadedImages count] - 1) inSection:0];
刷新某一行
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];
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];//选中后的反显颜色即刻消失
。。。。。。
}
待续。。。。