Iphone 表视图::无法删除自定义单元格中的自定义标签
在我的iPhone应用程序中 在表视图中 我在一个单元格中有两个标签Iphone 表视图::无法删除自定义单元格中的自定义标签,iphone,objective-c,xcode,cocoa-touch,uitableview,Iphone,Objective C,Xcode,Cocoa Touch,Uitableview,在我的iPhone应用程序中 在表视图中 我在一个单元格中有两个标签 默认的文本标签 自定义标签 数据正在从数组中删除,这很好 这是密码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //Get the Log Id for the sections. From Section Array int logID=0;
- (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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
//从节数组获取节的日志Id
int-logID=0;
if(indexPath.row==0)
{
NSLog(@“时间数组%@”,时间数组);
logID=[[sectionArray objectAtIndex:indexath.section]valueForKey:@“logID”]intValue];
NSPredicate*p=[NSPredicate谓词格式:@“logID==%d”,logID];
fillRows=零;
fillRows=[[timeArray filteredArrayUsingPredicate:p]mutableCopy];
}
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier]自动释放];
}
//显示当前时间。
//“如果条件为不转到数组索引越界”。
if(indexPath.rowif(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier]自动释放];
}
if(indexPath.row使用table的委托方法作为解决方案
- (void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径{
如果(editingStyle==UITableViewCellEditingStyleDelete)
{[array removeObjectAtIndex:indexPath.row];[tableview重载数据];}
你得到你想要的。答案是。。。
这就是为什么从te表中删除的单元格标签会粘在单元格上
请看我已经注释了两行代码
其中单元格==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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
//从节数组获取节的日志Id
静态NSString*CellIdentifier=@“Cell”;
**UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier]自动释放];
// }**
/if(indexath.rowNo)这不像是正确删除了数组对象,只是在删除…Alloc单元格后,上一个自定义标签仍会粘贴到该行,如下所示,请参见.static NSString*CellIdentifier=@“cell”;UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];if(cell==nil){cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier]自动释放];}
- (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;
}