滾動到指定行
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];
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];//選中後的反顯顏色即刻消失
。。。。。。
}
待續。。。。