Vladimir Samoilenko Vladimir Samoilenko - 1 year ago 100
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download