我的TableViewCell在我向上滚动表格后第一次没有加载内容它将显示完整视图。我在tableView中有五个部分(section = 1)遇到了这个问题。
我在这里附上了我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[super tableView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
在加载视图上
向上滚动
答案 0 :(得分:1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
return 10;
}
else if (section == 1)
{
return 10;
}
else
{
return 0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
{
if(section == 0)
{
return 40;
}
else if(section == 1)
{
return 40;
}
else
{
return 0;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *View=[[UIView alloc]initWithFrame:CGRectMake(0,0,768,40)];
View.backgroundColor=[UIColor colorWithRed:211.0/255.0 green:211.0/255.0 blue:211.0/255.0 alpha:1.0];
UILabel *lbl_title=[[UILabel alloc]initWithFrame:CGRectMake(10,0,700,40)];
lbl_title.backgroundColor=[UIColor clearColor];
lbl_title.font= [UIFont fontWithName:@"ArialMT" size:20];
lbl_title.textColor =[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];
if (section == 0)
{
lbl_title.text=@"Used";
}
else if (section == 1)
{
lbl_title.text=@"Expiring";
}
[View addSubview:lbl_title];
[lbl_title release];
return View;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (indexPath.section == 0)
{
UILabel *lbl=[[UILabel alloc]init];
lbl.frame=CGRectMake(180,10, 360, 60);
lbl.backgroundColor=[UIColor clearColor];
lbl.textColor = [UIColor blackColor];
lbl.numberOfLines = 3;
lbl.font = [UIFont fontWithName:@"ArialMT" size:18];
lbl.text = @"";
[cell.contentView addSubview:lbl];
[lbl release];
}
else if (indexPath.section == 1)
{
UILabel *lbl=[[UILabel alloc]init];
lbl.frame=CGRectMake(180,10, 360, 60);
lbl.backgroundColor=[UIColor clearColor];
lbl.textColor = [UIColor blackColor];
lbl.numberOfLines = 3;
lbl.font = [UIFont fontWithName:@"ArialMT" size:18];;
lbl.text = @"";
[cell.contentView addSubview:lbl];
[lbl release];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
答案 1 :(得分:0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = arrayValues[indexPath.row];
return cell;
}