//当tableView的cell数量改变后再次reload,contentOffset的值是通过预估各cell的高度及header、footer的高度后计算得到的,并非准确的值;所以需要关闭它。
1. self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
2. -(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{
//点击cell获取屏幕坐标
CGRectrectInTableView = [tableViewrectForRowAtIndexPath:indexPath];
CGRectrect = [tableViewconvertRect:rectInTableViewtoView:[tableViewsuperview]];
NSLog(@"%f%f",rect.origin.x,rect.origin.y);
NSString*selectRowStr = [NSStringstringWithFormat:@"%ld",indexPath.row];
NSLog(@"选择了第%@行",selectRowStr);
if(_selectRowAry.count!=0) {
NSString* row = [_selectRowAry objectAtIndex:0];
[_selectRowAry removeAllObjects];
if([rowisEqualToString:selectRowStr]) {
self.detailsView.hidden=YES;
}else{
[_selectRowAryaddObject:selectRowStr];
self.detailsView.hidden=NO;
CGFloatheigth = (rect.origin.y-27+DETAILSHEIGHT) - (self.view.bounds.size.height-55);
if(heigth >0) {
self.detailsView.frame=CGRectMake(ScreenWidth-DETAILSWIDTH-92, indexPath.row*55-heigth,DETAILSWIDTH,DETAILSHEIGHT);
}else{
self.detailsView.frame = CGRectMake(ScreenWidth-DETAILSWIDTH-92, indexPath.row *55+27, DETAILSWIDTH, DETAILSHEIGHT);
}
}
}else{
[_selectRowAryaddObject:selectRowStr];
self.detailsView.hidden=NO;
CGFloatheigth = (rect.origin.y-27+DETAILSHEIGHT) - (self.view.bounds.size.height-55);
if(heigth >0) {
self.detailsView.frame=CGRectMake(ScreenWidth-DETAILSWIDTH-92, indexPath.row*55-heigth,DETAILSWIDTH,DETAILSHEIGHT);
}else{
self.detailsView.frame = CGRectMake(ScreenWidth-DETAILSWIDTH-92, indexPath.row *55+27, DETAILSWIDTH, DETAILSHEIGHT);
}
}
}
网友评论