Vladimir Samoilenko Vladimir Samoilenko - 3 months ago 12
Objective-C Question

make non-move UITextField on background of UITableView

How to make UITextField on background of UITableView?
I want to set textField in the top and when i scroll tableView my textField don't move.

Something like this

- (void)viewDidLoad {
[super viewDidLoad];

self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 100, 30)];
self.textField.backgroundColor = [UIColor redColor];

self.tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
self.tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);

[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:NSStringFromClass([TableViewCell class])];

[self.view addSubview:self.textField];

}


enter image description here

Answer

You have another solution - besides one suggested in comments:

You can create UIViewController with tableView and text field. Assign delegate and dataSource to the view controller. Pin text field to the top and you have your desired behaviour. You will have to connect tableView with IBOutlets.

Comments