
1大部分的都是叫你将 estimatedRowHeight = 0;来关闭自动布局适配来解决,可这样又会让我的cell高度没法自适应所以我们采用只更新cell内容不更新高度的方式来解决。
用例如下: 点击cell的点赞功能,使点赞数量加1并点亮点赞的图标。
主要步骤在 利用indexpath获取你所点击的哪一行cell,然后重新赋值即可,就不用再去刷新整个tab或者固定的一行celll 了,这样他就不会去计算高度也就不会发生跳动了
myindexrow 是点击的inddexpathrow
NSIndexPathindexPath=[NSIndexPathindexPathForRow:myindexrow inSection:0]; mysquareCell1 mycell = [selfmytableview cellForRowAtIndexPath:indexPath] mycellmylabel9text= [NSStringstringWithFormat:@"%ld",(long)(mymodup_like- mymoddown_like)];
mylabel9就是你想要刷新后改变的值。
1.新建TableViewCell类,继承父类为UITableViewCell 11 "TableCellh"#import <UIKit/UIKith> / 房间桌子显示结构 /@interface TableCell : UITableViewCell { UILabel tableNoLable; // 桌子号 UIImageView tableImageView; // 桌子 UIImageView tableStateImageView; // 桌子状态}@property (nonatomic ,retain) IBOutlet UILabel tableNoLable;// 桌子号@property (nonatomic ,retain) IBOutlet UIImageView tableImageView;// 桌子@property (nonatomic ,retain) IBOutlet UIImageView tableStateImageView;// 桌子状态12 TableCell m#import "TableCellh"@implementation TableCell@synthesize tableNoLable; // 桌子号@synthesize tableImageView; // 桌子@synthesize tableStateImageView; // 桌子状态- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString )reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { // Initialization code } return self;}- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state}- (void)dealloc { [tableNoLable release]; [tableImageView release]; [hand3ImageView release]; [super dealloc];}@end13 布置布局文件( xib 文件)指明 class 为自己定义的 tabelcellviewnew 一个Empty Xib文件,其中不包含view, 在libriary中拖一个UITableCell到两个图标的框中,双击cellview,指明class为cellm文件,开始编辑2 页面中在 tableView 中加载自己的 cell #import "TableCellh"// 设置房间桌子数-(NSInteger)tableView:(UITableView )tableView numberOfRowsInSection:(NSInteger)section{ [Util showLog:@"numberOfRowsInSection"]; return g_RoomwTableCount;}// 设置单元格的高度-(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{ [Util showLog:@"heightForRowAtIndexPath"]; return kTableViewRowHeight;}// 设置单元个样式-(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath{ [Util showLog:@"cellForRowAtIndexPath start"]; static NSString tableCellIdentifier = @"TableCellIdentifier"; TableCell cell = (TableCell )[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier]; [Util showLog:@"TableCellIdentifier"]; if(cell == nil){ NSArray nib = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil]; for(id oneObject in nib){ if([oneObject isKindOfClass:[TableCell class]]){ cell = (TableCell )oneObject;// 自己设计每个 cell 的内容,此函数会回调 table 的行数次,行数为 numberOfRowsInSection:(NSInteger)section 函数指定 // 显示桌子号码 NSUInteger row = [indexPath row] + 1; NSString str =[NSString stringWithFormat:@"%d",row]; celltableNoLabletext = [[@" 第 " stringByAppendingString:str] stringByAppendingString:@" 桌 "]; [Util showLog:@"tableNoLable"]; if(deskshowFlg){ // 获取要绘画的桌子信息 Desk tempDesk = [g_DeskArray objectAtIndex:[indexPath row]]; } } }
直接用tableview的datasource的numberOfSectionsInTableView和numberOfRowsInSection就可以取到最后一个cell的indexPath,再跟目标cell的indexPath一比就行了。
点击一个cell 高度增加,tableview初始化是4个cell的大小,当点击第四个cell的时候 高度增加了,cell里增加的部分在tableview的下面,看不到了,需要向上拖动tableview才行,这样用户体验不好。
现在的情况是,点击一个cell时,增加了高度,当点击的下一个cell在上次点击的cell的下面,高度增加的时候是向上的方向上增加的,如果在上次点击的cell上面就向下的方向增加,能不能自动判断当前cell在tableview中的位置,
根据当前位置决定增加高度的方向。
present和push都是需要controller才能完成跳转。
所以就有几种方法可以用:
1、把你要跳转的意图传给tableview所在的controller。可以用通知,block,代理方法,只要能把消息传出去就行。在tableview所在的controller进行跳转
2、获取cell所在的controller,在cell中进行跳转。
- (UIViewController )getSuperController{
UIViewController vc = [[UIViewController alloc]init];
for (UIView next = [self superview]; next; next = nextsuperview) {
UIResponder nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
vc = (UIViewController)nextResponder;
break;
}
}
return vc;
}
UIViewController vc = [self getSuperController];
用获得的vc进行跳转。
望采纳!
以上就是关于IOS 解决UITableView使用estimatedRowHeight后cell刷新后会跳动的问题全部的内容,包括:IOS 解决UITableView使用estimatedRowHeight后cell刷新后会跳动的问题、如何iOS 编程中使用自定义 TableViewCell、iOS 比如在tableview中存在100个cell,怎么判断当前cell是在这100个中的第几个等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)