Bar*_*rtu 0 iphone delegates uitableview ios
我正在使用a UITableViewController,我想要做的是在下面添加一个自定义工具栏UIView.
我已经尝试启用navigationController(下面的代码)的工具栏,但它似乎无法正常工作.UITextField不会调用代理,文本字段的按键不会显示在文本字段中.
使用像这样的工具栏不是我的第一选择,我想在我的UITableViewController下我的自定义视图,我可以放置我的项目,就像一个UIToolbar.(保持为UIView页脚)
码:
self.navigationController.toolbarHidden = NO;
// create toolbar objects
UITextField *inputField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 230, 31)];
inputField.backgroundColor = [UIColor clearColor];
inputField.borderStyle = UITextBorderStyleRoundedRect;
inputField.inputAccessoryView = self.navigationController.toolbar;
inputField.returnKeyType = UIReturnKeyDone;
inputField.delegate = self;
UIButton *sendButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
sendButton.titleLabel.text = @"Send";
sendButton.backgroundColor = [UIColor greenColor];
// add objects into navigation controller
self.toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithCustomView:inputField],
[[UIBarButtonItem alloc] initWithCustomView:sendButton], nil];
Run Code Online (Sandbox Code Playgroud)
UITableViewController您可能会发现将子类化为子类并向其UIViewController添加a 更容易,而不是为您的实现创建子类UITableView.这样可以在自定义布局方面提供更大的灵活性.
基本上步骤是:
这样你就可以将inputField和button添加到viewController的视图中(在底部),它们不会滚动,因为它们与tableview是分开的.
| 归档时间: |
|
| 查看次数: |
1997 次 |
| 最近记录: |