表格视图::无法删除自定义单元格中的自定义标签 [英] table view :: could not delete the custom label in custom cell
本文介绍了表格视图::无法删除自定义单元格中的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的iPhone应用程序中,
In my iPhone app,
在表格"视图中
我在一个单元格中有两个标签.
I have Two labels in one cell..
- 默认的textLabel.
- 自定义标签
数据正在从数组中删除,这很好...
Data is deleting from array which is fine...
这里是代码.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the Log Id for the sections. From Section Array
int logID=0;
if(indexPath.row==0)
{
NSLog(@"Time Array %@",timeArray);
logID=[[[sectionArray objectAtIndex:indexPath.section] valueForKey:@"logID"] intValue];
NSPredicate *p=[NSPredicate predicateWithFormat:@"logID==%d",logID];
fillRows=nil;
fillRows= [[timeArray filteredArrayUsingPredicate:p] mutableCopy];
}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
//Show Current Time.
//"If condition for not to go for Array Index Out of Bound".
if(indexPath.row<[fillRows count])
{
//Log CurrentTime
cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"];
[cell.textLabel setTextColor:[UIColor whiteColor]];
//Log Duration.
UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease];
[lblDuration setTextColor:[UIColor whiteColor]];
[lblDuration setBackgroundColor:[UIColor clearColor]];
[lblDuration setFont:[UIFont boldSystemFontOfSize:18]];
lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"];
[cell.contentView addSubview:lblDuration];
}
return cell;
}
先谢谢您了:)
推荐答案
答案是这个...那就是为什么从te表中删除的单元格的标签粘贴到该单元格上的原因...
Answer is this... that why the label of the cell which was deleted from te table stuck to the cell...
只看我已经注释了两行代码……
Just see I have commented two lines of codes......
其中cell == nil ..
Where cell==nil..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the Log Id for the sections. From Section Array
static NSString *CellIdentifier = @"Cell";
**UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
// }**
/if(indexPath.row<[fillRows count])
{
//Log CurrentTime
cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"];
[cell.textLabel setTextColor:[UIColor whiteColor]];
//Log Duration.
UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease];
[lblDuration setTextColor:[UIColor whiteColor]];
[lblDuration setBackgroundColor:[UIColor clearColor]];
[lblDuration setFont:[UIFont boldSystemFontOfSize:18]];
lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"];
[cell.contentView addSubview:lblDuration];
}
return cell;
}
这篇关于表格视图::无法删除自定义单元格中的自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文