在表格视图上添加文本字段和复选框

发布于 2024-12-04 17:52:39 字数 108 浏览 0 评论 0原文

在我的 iPhone 应用程序中,我必须在两行表格视图中添加文本字段,并在一行中添加一个复选框。谁能给我提供一个可以帮助我的例子。我是 iPhone 新手,不知道如何开始。

提前致谢..

In my Iphone app I have to add textfield at two rows of tableview and a checkbox to one row. Can anyone provide me an example that can help me. I am new on Iphone and I don't know how to start with this.

Thanks in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

波浪屿的海角声 2024-12-11 17:52:39

中试试这个,

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

嘿,在你的 cellForRowAtindexPath {

UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]];
if (!cell){
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]] autorelease];  
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

if(indexPath.row == 0){
            //  NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"];
            UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)];
            text0.textAlignment = UITextAlignmentLeft;
            text0.backgroundColor = [UIColor whiteColor];
            text0.borderStyle = UITextBorderStyleNone;
            text0.userInteractionEnabled = FALSE;
            text0.font = [UIFont boldSystemFontOfSize:17];
            text0.textColor = [UIColor blackColor];
            text0.delegate = self;
            text0.text = @"Type de Parteneria";
            [cell addSubview:text0];

            UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectMake(120, 12, 160, 20)];
            text1.textAlignment = UITextAlignmentRight;
            text1.borderStyle = UITextBorderStyleNone;
            text1.backgroundColor = [UIColor whiteColor];
            text1.userInteractionEnabled = TRUE;
            text1.font = [UIFont boldSystemFontOfSize:16];
            text1.textColor = [UIColor colorWithRed:114.0f/255.0f green:136.0f/255.0f blue:165.0f/255.0f alpha:1.0];
            text1.delegate = self;

            [cell addSubview:text1];

    }
    else if(indexPath.row == 1){
            //  NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"];
            UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)];
            text0.textAlignment = UITextAlignmentLeft;
            text0.backgroundColor = [UIColor whiteColor];
            text0.borderStyle = UITextBorderStyleNone;
            text0.userInteractionEnabled = FALSE;
            text0.font = [UIFont boldSystemFontOfSize:17];
            text0.textColor = [UIColor blackColor];
            text0.delegate = self;
            text0.text = @"Audi R8";
            [cell addSubview:text0];


            UIButton *signBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        signBtn.frame = CGRectMake(15, 170, 290, 35);
        [signBtn setTitle:@"Sign Up" forState:UIControlStateNormal];
        [signBtn setBackgroundImage:[UIImage imageNamed:@"CheckBox.png"] forState:UIControlStateNormal];
        [signBtn setFont:[UIFont boldSystemFontOfSize:17]];
        [signBtn addTarget:self action:@selector(checkPressed) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:signBtn];
    }
   return cell;

}

如果你遇到问题,请给我发消息

Hey try this one in your cellForRowAtindexPath

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

{

UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]];
if (!cell){
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]] autorelease];  
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

if(indexPath.row == 0){
            //  NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"];
            UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)];
            text0.textAlignment = UITextAlignmentLeft;
            text0.backgroundColor = [UIColor whiteColor];
            text0.borderStyle = UITextBorderStyleNone;
            text0.userInteractionEnabled = FALSE;
            text0.font = [UIFont boldSystemFontOfSize:17];
            text0.textColor = [UIColor blackColor];
            text0.delegate = self;
            text0.text = @"Type de Parteneria";
            [cell addSubview:text0];

            UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectMake(120, 12, 160, 20)];
            text1.textAlignment = UITextAlignmentRight;
            text1.borderStyle = UITextBorderStyleNone;
            text1.backgroundColor = [UIColor whiteColor];
            text1.userInteractionEnabled = TRUE;
            text1.font = [UIFont boldSystemFontOfSize:16];
            text1.textColor = [UIColor colorWithRed:114.0f/255.0f green:136.0f/255.0f blue:165.0f/255.0f alpha:1.0];
            text1.delegate = self;

            [cell addSubview:text1];

    }
    else if(indexPath.row == 1){
            //  NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"];
            UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)];
            text0.textAlignment = UITextAlignmentLeft;
            text0.backgroundColor = [UIColor whiteColor];
            text0.borderStyle = UITextBorderStyleNone;
            text0.userInteractionEnabled = FALSE;
            text0.font = [UIFont boldSystemFontOfSize:17];
            text0.textColor = [UIColor blackColor];
            text0.delegate = self;
            text0.text = @"Audi R8";
            [cell addSubview:text0];


            UIButton *signBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        signBtn.frame = CGRectMake(15, 170, 290, 35);
        [signBtn setTitle:@"Sign Up" forState:UIControlStateNormal];
        [signBtn setBackgroundImage:[UIImage imageNamed:@"CheckBox.png"] forState:UIControlStateNormal];
        [signBtn setFont:[UIFont boldSystemFontOfSize:17]];
        [signBtn addTarget:self action:@selector(checkPressed) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:signBtn];
    }
   return cell;

}

If you get problem than message me

心凉 2024-12-11 17:52:39

根据你的评论尝试这个:

if(indexPath.row==1)
{
  UITextField *labl=[[UITextField alloc] init];
  // where is your text field's frame ???? 
  labl.frame = CGRectMake(10,10,50,50);
  labl.text=@"data"; 
  [cell addSubview:labl]; 
}

as per your comment try this :

if(indexPath.row==1)
{
  UITextField *labl=[[UITextField alloc] init];
  // where is your text field's frame ???? 
  labl.frame = CGRectMake(10,10,50,50);
  labl.text=@"data"; 
  [cell addSubview:labl]; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文