0
我使用了UINavigationController pushViewController來呈現ViewController,在viewcontroller的視圖中,有一個UITablView。 我用下面的代碼在UITableViewCell上繪製UILabel,但它不顯示,只有當我點擊UIlabel所在的行時,它纔會出現,如果我點擊另一行,它會再次消失。奇怪的問題在UITableViewCell上繪製標籤
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier1 = @"CellTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier1 ];
if (cell == nil)
{
cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:SimpleTableIdentifier1] autorelease];
switch([[myArray objectAtIndex:indexPath.row] getValueType])
{
case _PSToggleSwitchSpecifier:
{
UISwitch *switchview=[[UISwitch alloc]init];
switchview.tag=11106 ;
cell.accessoryView= switchview;
//switchview.frame=CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
//[cell.contentView addSubview:switchview];
[switchview addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[switchview release];
break;
}
case _PSMultiValueSpecifier:
{
cell.accessoryType= UITableViewCellAccessoryDisclosureIndicator;//
//draw a label, but actually it does display,
UILabel *labelCell =[ [UILabel alloc]init];
[labelCell setTag:11101];
labelCell.frame = CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
[labelCell setBackgroundColor:[UIColor clearColor]];
labelCell.textAlignment=UITextAlignmentRight;
[labelCell setFont:[UIFont systemFontOfSize:18.0]];
[labelCell setTextColor:[UIColor blackColor]];
[cell.contentView addSubview:labelCell];
[labelCell release];
break;
}
}
}
[email protected]"test";
switch([[myArray objectAtIndex:indexPath.row] getValueType])
{
case _PSToggleSwitchSpecifier:
{
cell.accessoryType=UITableViewCellAccessoryNone;//
UISwitch *tem=(UISwitch*) [cell.contentView viewWithTag:11106];//cell.accessoryView;//
tem.on= true;
break;
}
case _PSMultiValueSpecifier:
{
UILabel *newLabelCell=(UILabel*)[cell.contentView viewWithTag: 11101];//intV];
[email protected]"Items";//it should display, but actually not, only when I tap the row "didselect" the text display
break;
}
};
return cell;
}
在上面UISwitch代碼顯示,但如果我使用代碼
switchview.frame=CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
[switchview addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:switchview];
更換cell.accessoryView= switchview;
UISwitch將是同樣的事情的UILabel
歡迎任何評論
謝謝
InterDev中