本文介绍了滚动更多时间时UiTbleview单元重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 UITableView
在视图中显示不同的数据.我正在使用由.m文件中的代码创建的 UITableViewCell
.它们总共是9种不同类型的单元格,其单元格的高度和标识符为0.当表格中具有两个不同高度的同一单元格开始相互重叠.
I am using UITableView
for displaying different data in the view. I am using UITableViewCell
created by code in the .m file. Their are total 9 different kind of cell with 0 different identifiers and heights for the cell. when the same cell with two different heights in the table it start overlapping each other.
在这里,我将代码放到单元格方法的高度.
Here I am putting the code for the height of the cell method.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row ==0)
{
return 120.0;
}
else{
//For Action User follow
if(condition)
{
//Checking if the Follow is shared or not
if()
{
//Checking the number of Counts
if()
{
if()
{
if()
{
return 340.0+(arTemp1.count*50.0);
}
else
{
return 157.0+(arTemp1.count*50.0);
}
}
else
{
if()
{
return 340.0+200;
}
else
{
return 157.0+200;
}
}
}
else
{
if( )
{
return 340.0f;
}
else{
return 157.0f;
}
}
}
else
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
if()
{
height=height+150;
}
return height+(arTemp1.count*50.0);
}
else
{
if( )
{
height= height;
}
return height;
}
}
else
{
if()
{
height= height+40;
}
return height;
}
}
}
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 160.0+(arTemp1.count*50.0);
}
else
{
return 160.0+200;
}
}
else
{
return 150.0f;
}
}
//For Action Add New Reciepe
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 420.0+(arTemp1.count*50.0);
}
else
{
return 420.0+200;
}
}
else
{
return 400.0f;
}
}
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 350.0+(arTemp1.count*50.0);
}
else
{
return 350.0+200;
}
}
else
{
return 350.0f;
}
}
//For Action Added new page
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 350.0+(arTemp1.count*50.0);
}
else
{
return 350.0+200;
}
}
else
{
return 350.0f;
}
}
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 170.0+(arTemp1.count*50.0);
}
else
{
return 150.0+200;
}
}
else
{
return 150.0f;
}
}
//For Action Add Photo
else if ()
{
if(arTemp1.count>0)
{
if(arTemp1.count <4)
{
return 350.0+(arTemp1.count*50.0);
}
else
{
return 350.0+200;
}
}
else
{
return 350.0f;
}
}
}
return 0.0f;
}
行代码单元格
NSString *CellIdentifier = @"a";
UITableViewCell *a = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (a == nil)
{
//Follow Cell Initializing
a = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
a.selectionStyle = UITableViewCellSelectionStyleNone;
a.tag=a;
//Create Cell Method
[self aCreateCell:a atIndexPath:indexPath];
}
// Set Cell Method
[self aSetCell:a atIndexPath:indexPath];
[a setClipsToBounds:YES];
return a;
推荐答案
尝试一下
首先,您要使用tableView注册单元格类
First you register your cell class with tableView
- (void)viewDidLoad{
/*IF You are using class */
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellIdentifire"];
/* if you are using nib */
// LOAD UP THE NIB FILE FOR THE CELL
UINib *nib = [UINib nibWithNibName:@"CustomNibCell" bundle:nil];
// REGISTER THE NIB FOR THE CELL WITH THE TABLE
[self.tableView registerNib:nib forCellWithReuseIdentifier:@"cellIdentifire"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifire" forIndexPath:indexPath];
/*
Write code
cell.title= @"hello";
*/
return cell;
}
这篇关于滚动更多时间时UiTbleview单元重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!