0

I just started Xcode objective-c recently and right now I'm trying to create a tableview with textfields in them to type. Ive looked into other stack overflow questions but many are from 6-8 years ago and seem to have a wide rage of answers and extremely complex. Could someone help me with the basics of how I can insert a textfield in a table view and give me some advice. Thanks!

1
  • just drag and drop uitextfield in UITableViewCell through storyboard Commented Jun 29, 2017 at 10:19

4 Answers 4

1

Write this code in uitableview cell

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.delegate = self;  
[aCell.contentView addSubview:txt];
Sign up to request clarification or add additional context in comments.

Comments

1

You can do this as follows:

  1. Drag and drop a UITableView in to your view
  2. Drag and drop a UITableViewCell into your table.
  3. Drag and drop a UITextField (or any other UI component that you need)

I would suggest you to please refer tutorials for that like

1.https://videos.raywenderlich.com/courses/22-table-views-in-ios/lessons/8 2.https://www.appcoda.com/expandable-table-view/

They have best tutorials with all steps you can easily do whatever you want.

I hope it will help you.

Thanks.

3 Comments

I have update answer with proper tutorial link. and apdating appcode link too for the same.
Welcome Calvin.
Hello @CalvinChang Please mark answer as a right if you got any help with this answer. Thanks a lot.
0

Try below code

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

    if (cell == nil) {

        /*
         *   Actually create a new cell (with an identifier so that it can be dequeued).
         */

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    /*
     *   Now that we have a cell we can configure it to display the data corresponding to
     *   this row/section
     */

    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(45, 30, 200, 40)];
    tf.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
    tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
    tf.backgroundColor=[UIColor whiteColor];
    tf.text=@"Hello World";
    [cell.contentView addSubview:tf];

    /* Now that the cell is configured we return it to the table view so that it can display it */

    return cell;

}

Comments

0

You can create a custom cell. Add the textfield in it and use that in the table by registering the nib or class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.