Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone中侧面桌面视图中的文本视图覆盖_Iphone_Objective C_Ios - Fatal编程技术网

iphone中侧面桌面视图中的文本视图覆盖

iphone中侧面桌面视图中的文本视图覆盖,iphone,objective-c,ios,Iphone,Objective C,Ios,我使用以下代码在tableview中显示一些标签和textview。但问题是一些文本视图在滚动时在一些不需要的地方被覆盖。请帮帮我。提前谢谢 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell

我使用以下代码在tableview中显示一些标签和textview。但问题是一些文本视图在滚动时在一些不需要的地方被覆盖。请帮帮我。提前谢谢

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.selectionStyle                                         =   UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor whiteColor];
    if (indexPath.row==0) 
    {
        UILabel *Sender = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 20)];
        Sender.text=@"From Time";
        Sender.textColor=[UIColor colorWithRed:77.0/255.0 green:104.0/255.0 blue:159.0/255.0 alpha:1.0]; 
        Sender.font=[UIFont fontWithName:@"verdana" size:16];
        [cell addSubview:Sender];
        [Sender release];  

    }

    if (indexPath.row==1) 
    {
        UILabel *Sender = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 20)];
        Sender.text=@"Sender";
        Sender.textColor=[UIColor colorWithRed:77.0/255.0 green:104.0/255.0 blue:159.0/255.0 alpha:1.0]; 
        Sender.font=[UIFont fontWithName:@"verdana" size:16];
        [cell addSubview:Sender];
        [Sender release];  
        UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(30, 35, 200, 20)];
        Label.text=@"Achuthananthan";
        Label.font=[UIFont fontWithName:@"verdana" size:14];
        [cell addSubview:Label];
        [Label release]; 
    }
    if (indexPath.row==2) 
    {
        UILabel *Agenda = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 20)];
        Agenda.text=@"Agenda";
        Agenda.textColor=[UIColor colorWithRed:77.0/255.0 green:104.0/255.0 blue:159.0/255.0 alpha:1.0]; 
        Agenda.font=[UIFont fontWithName:@"verdana" size:16];

        [cell addSubview:Agenda];
        [Agenda release]; 
        UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 30, 280, 120)];
        textView.editable=NO;
        textView.text=[NSString stringWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."];
        textView.font=[UIFont fontWithName:@"verdana" size:14];
        [cell addSubview:textView];

        [textView release];

    }
    return cell;
}

将添加视图的代码移动到
if(cell==nil){
节中

例如,如果要添加
ui标签
,请执行以下操作

UILabel *label;
if (cell == nil) {
    //create the cell
    //Create the label
    //Give the label a tag
    label.tag = 111; //for example
    //add label to the cell
    [cell.contentView addSubView:label];
}

//Now get the label of the cell
label = (UILabel*) [cell viewWithTag:111];
对要添加到单元格的所有UILabel和其他视图重复此操作使用此代码

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle =   UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor whiteColor];

 UILabel *Sender = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 20)];
     [sender setTag:500];
Sender.font=[UIFont fontWithName:@"verdana" size:16];
    Sender.textColor=[UIColor colorWithRed:77.0/255.0 green:104.0/255.0 blue:159.0/255.0 alpha:1.0]; 
    [cell addSubview:Sender];
    [Sender release];  

    UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(30, 35, 200, 20)];
    Label.text=@"Achuthananthan";
    Label.font=[UIFont fontWithName:@"verdana" size:14];
    [Label setTag:600];
    [cell addSubview:Label];
    [Label release]; 

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 30, 280, 120)];
    textView.editable=NO;
[Label setTag:700];
    textView.text=[NSString stringWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."];
    textView.font=[UIFont fontWithName:@"verdana" size:14];
    [cell addSubview:textView];
    [textView release];

}

UILabel *firstLabel = (UILabel*)[cell viewWithTag:500];
UILabel *SecondLabel = (UILabel*)[cell viewWithTag:600];
UITextView *firstText = (UITextView*)[cell viewWithTag:700];

if (indexPath.row==0) 
{

    firstLabel.text=@"From Time";
[SecondLabel setHidden:Yes];
[firstText setHidden:Yes];

}

if (indexPath.row==1) 
{

    firstLabel.text=@"Sender";
[SecondLabel setHidden:NO];
[firstText setHidden:Yes];

}
if (indexPath.row==2) 
{
    firstLabel.text=@"Agenda";
[SecondLabel setHidden:Yes];
[firstText setHidden:NO]; 
}
return cell;
 }

现在列为空。不工作。无论如何,谢谢您的支持answer@Melbourne:我认为您一定没有正确使用它。否则问题就解决了。您可以显示您已执行的新代码吗?内容(标签和文本视图)是否显示在单元格上??