删除“;Rowatindexpath的高度”;对于iOS8
我花了两天时间试图解决这个问题,然后才找到解决办法。 给你 ====== 大家好, 实际上,我在iOS7中使用委托方法heightforrowatinexpath管理tableViewCell的高度: 现在,在iOS8中,我将tableView.rowHeight=UITableViewAutomaticDimension属性与autolayout一起使用,它的效果比以前更好 问题是我需要从代码中删除heightforrowatinexpath:method,否则该属性不起作用(height在内部设置并控制该属性) 如何仅在iOS8中删除此方法(可能使用编译指令,但我不知道是哪一个) 我仍然需要它删除“;Rowatindexpath的高度”;对于iOS8,ios,ios7,ios8,deprecated,heightforrowatindexpath,Ios,Ios7,Ios8,Deprecated,Heightforrowatindexpath,我花了两天时间试图解决这个问题,然后才找到解决办法。 给你 ====== 大家好, 实际上,我在iOS7中使用委托方法heightforrowatinexpath管理tableViewCell的高度: 现在,在iOS8中,我将tableView.rowHeight=UITableViewAutomaticDimension属性与autolayout一起使用,它的效果比以前更好 问题是我需要从代码中删除heightforrowatinexpath:method,否则该属性不起作用(height在内
我也有这个问题,请看这里: 1) 我们需要创建宏
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
2) 需要在视图中检查的版本将出现
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.p_tableView respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)])
{
self.p_tableView.rowHeight = UITableViewAutomaticDimension;
self.p_tableView.estimatedRowHeight = 100.0f;
}
}
3) 我们需要重写respondsToSelector方法,这样需要更少的资源消耗,因为我们不需要为每一行调用heightForRow
- (BOOL)respondsToSelector:(SEL)selector
{
static BOOL useSelector;
static dispatch_once_t predicate = 0;
dispatch_once(&predicate, ^{
useSelector = SYSTEM_VERSION_LESS_THAN(@"8.0");
});
if (selector == @selector(tableView:heightForRowAtIndexPath:))
{
return useSelector;
}
return [super respondsToSelector:selector];
}
希望能有帮助
我也有这个问题,请看这里: 1) 我们需要创建宏
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
2) 需要在视图中检查的版本将出现
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.p_tableView respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)])
{
self.p_tableView.rowHeight = UITableViewAutomaticDimension;
self.p_tableView.estimatedRowHeight = 100.0f;
}
}
3) 我们需要重写respondsToSelector方法,这样需要更少的资源消耗,因为我们不需要为每一行调用heightForRow
- (BOOL)respondsToSelector:(SEL)selector
{
static BOOL useSelector;
static dispatch_once_t predicate = 0;
dispatch_once(&predicate, ^{
useSelector = SYSTEM_VERSION_LESS_THAN(@"8.0");
});
if (selector == @selector(tableView:heightForRowAtIndexPath:))
{
return useSelector;
}
return [super respondsToSelector:selector];
}
希望能有帮助
您仍然可以使用
tableView:heightforrow索引路径:
- (void)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
您仍然可以使用
tableView:heightforrow索引路径:
- (void)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
试试这个
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(IS_IOS8){
return UITableViewAutomaticDimension;
}
else
{
int height; // your custom calculated height
return height;
}
}
试试这个
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(IS_IOS8){
return UITableViewAutomaticDimension;
}
else
{
int height; // your custom calculated height
return height;
}
}
为什么不保持它的简单性,只需从索引路径的高度返回
UITableViewAutomaticDimension
?不需要特定于版本的测试。为什么不保持简单,只需从heightforrowatinexpath
返回UITableViewAutomaticDimension
?不需要特定版本的测试。