我已经在xcode 4中完成了我的应用程序编码,但我正在尝试在xcode 5上的这个代码在UITableview中出现很多问题。表格行和表格内容不可见。通常表格显示正确,但我在tableview中为子视图设置水平和分隔线,时间范围只设置行和内容不可见。
在图片中,我将桌面视图的背景颜色设置为蓝色,因此此内容区域仅以白色显示
{
UIView *subView=[[UIView alloc]initWithFrame:CGRectMake(5, 0, 510, ([subViewsDataArr count] * 50) + 10)];
subView.backgroundColor=[UIColor clearColor];
subView.layer.borderWidth = 1;
subView.layer.borderColor = [[UIColor blackColor] CGColor];
subView.layer.cornerRadius=5;
[myCell addSubview:subView];
int y = 5;
for (int j=0; j<[subViewsDataArr count]; j++, y = y+50) {
UIView *cellView =[[UIView alloc] init];
cellView.frame =CGRectMake(5, y, 500, 50);
cellView.backgroundColor =[UIColor clearColor];
[subView addSubview:cellView];
if (j == 0)
{
int x =-1;
UIImageView *horizontalLineImgStart =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 1)];
horizontalLineImgStart.image =[UIImage imageNamed:@"horizontalLine.png"];
[cellView addSubview:horizontalLineImgStart];
UIImageView *seperatorLineImgStart =[[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 1, 50)];
seperatorLineImgStart.image =[UIImage imageNamed:@"seperatorLine.png"];
[cellView addSubview:seperatorLineImgStart];
for (int i=0; i < 8; i++) {
UILabel *cellLbl = [[UILabel alloc] init];
[cellLbl setText:[NSString stringWithFormat:@"%@",[[subViewsDataArr objectAtIndex:j] objectAtIndex:i]]];
cellLbl.textAlignment =UITextAlignmentCenter;
if (i == 0 || i == 1 || i == 4 || i == 5 || i == 6 || i == 7) {
cellLbl.font =[UIFont fontWithName:@"Helvetica Bold" size:12];
cellLbl.numberOfLines =2;
}
else
{
cellLbl.adjustsFontSizeToFitWidth =YES;
cellLbl.font =[UIFont fontWithName:@"Helvetica Bold" size:10];
}
[cellLbl setBackgroundColor:[UIColor clearColor]];
cellLbl.textColor =[UIColor grayColor];
[cellView addSubview:cellLbl];
UIImageView *seperatorLineImg =[[UIImageView alloc] init];
if (i == 0 || i == 1 || i == 2 || i == 5)
{
cellLbl.frame = CGRectMake(x + 1, 5, 55, 40);
seperatorLineImg.frame =CGRectMake(x + 55, 0, 1, 50);
x = x + 55;
}
else if (i == 6 || i == 7)
{
cellLbl.frame = CGRectMake(x + 1, 5, 80, 40);
seperatorLineImg.frame =CGRectMake(x + 80, 0, 1, 50);
x = x + 80;
}
else
{
cellLbl.frame = CGRectMake(x + 1, 5, 60, 40);
seperatorLineImg.frame =CGRectMake(x + 60, 0, 1, 50);
x = x + 60;
}
seperatorLineImg.image =[UIImage imageNamed:@"seperatorLine.png"];
[cellView addSubview:seperatorLineImg];
}
UIImageView *horizontalLineImgEnd =[[UIImageView alloc] initWithFrame:CGRectMake(0, 50, 500, 1)];
horizontalLineImgEnd.image =[UIImage imageNamed:@"horizontalLine.png"];
[cellView addSubview:horizontalLineImgEnd];
}
else
{
int x =-1;
UIImageView *horizontalLineImgStart =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 1)];
horizontalLineImgStart.image =[UIImage imageNamed:@"horizontalLine.png"];
[cellView addSubview:horizontalLineImgStart];
UIImageView *seperatorLineImgStart =[[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 1, 50)];
seperatorLineImgStart.image =[UIImage imageNamed:@"seperatorLine.png"];
[cellView addSubview:seperatorLineImgStart];
for (int i=0; i < 8; i++ , txtFldTagVal= txtFldTagVal + 1) {
UITextField *cellTxtFld = [[UITextField alloc] init];
cellTxtFld.text =[NSString stringWithFormat:@"%@",[[subViewsDataArr objectAtIndex:j] objectAtIndex:i]];
cellTxtFld.textAlignment =UITextAlignmentCenter;
cellTxtFld.font =[UIFont fontWithName:@"Helvetica Bold" size:12];
[cellTxtFld setBackgroundColor:[UIColor clearColor]];
cellTxtFld.textColor =[UIColor brownColor];
cellTxtFld.tag =5000 + txtFldTagVal;
cellTxtFld.delegate =self;
cellTxtFld.adjustsFontSizeToFitWidth = YES;
[cellView addSubview:cellTxtFld];
UIImageView *seperatorLineImg =[[UIImageView alloc] init];
if (i == 0 || i == 1 || i == 2 || i == 5)
{
cellTxtFld.frame = CGRectMake(x + 1, 5, 55, 40);
seperatorLineImg.frame =CGRectMake(x + 55, 0, 1, 50);
x = x + 55;
}
else if (i == 6 || i == 7)
{
cellTxtFld.frame = CGRectMake(x + 1, 5, 80, 40);
seperatorLineImg.frame =CGRectMake(x + 80, 0, 1, 50);
x = x + 80;
}
else
{
cellTxtFld.frame = CGRectMake(x + 1, 5, 60, 40);
seperatorLineImg.frame =CGRectMake(x + 60, 0, 1, 50);
x = x + 60;
}
seperatorLineImg.image =[UIImage imageNamed:@"seperatorLine.png"];
[cellView addSubview:seperatorLineImg];
}
UIImageView *horizontalLineImgEnd =[[UIImageView alloc] initWithFrame:CGRectMake(0, 50, 500, 1)];
horizontalLineImgEnd.image =[UIImage imageNamed:@"horizontalLine.png"];
[cellView addSubview:horizontalLineImgEnd];
}
}
}
答案 0 :(得分:0)
我认为您在表格单元格中添加了一些内容,例如removeFromSuperView,以便只有该视图不可见,请删除以下代码(如果代码中有代码)
[myCell.subviews makeObjectsPerformSelector:@ selector(removeFromSuperview)]; [myCell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];