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!
4 Answers
You can do this as follows:
- Drag and drop a UITableView in to your view
- Drag and drop a UITableViewCell into your table.
- 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
Samkit Shah
I have update answer with proper tutorial link. and apdating appcode link too for the same.
Samkit Shah
Welcome Calvin.
Samkit Shah
Hello @CalvinChang Please mark answer as a right if you got any help with this answer. Thanks a lot.
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;
}
UITableViewCellthrough storyboard