iPhone中侧面视图中的Textview覆盖 [英] Textview in side tableview overwriting in iphone

查看:32
本文介绍了iPhone中侧面视图中的Textview覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在表视图中显示一些标签和一个文本视图.但是问题是滚动时某些textview在一些不需要的地方被覆盖了.请帮我 .预先感谢

I am using the following code to show some labels and a textview in a tableview. But the problem is some textviews overwriting at some unwanted places while scrolling. Please help me . Thanks in advance

- (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;
}

推荐答案

使用此代码...

 - (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;
 }

这篇关于iPhone中侧面视图中的Textview覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆