我正在研究一个项目,我必须更改旧代码并使用已完成的工作,
我通过解析Json来收集信息(item, label ..
),
在旧代码中,我们有一个模态视图,它分为两部分:第一部分显示项目的图片,第二部分是带有多个按钮和搜索栏的表格视图,
我要做的就是拆分它,
我需要在另一个表视图中设置搜索栏,我点击一个按钮,当我点击一个搜索栏时,它会推动另一个显示地图的视图控制器, 问题是使用故事板所做的事情,我必须以编程方式完成! 我该怎么办?
答案 0 :(得分:0)
您可以通过向其发送removeFromSuperview消息以编程方式删除UISearchBar,然后继续创建它的新实例并相应地放置它。
答案 1 :(得分:0)
您可以以非常简单的方式将UISearchBar设置为tableView的标头。 例如。像这样定义你的搜索栏
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
self.searchBar.barTintColor = weAskDefaultBkgColor;
self.searchBar.placeholder = @"Search users by their name or username";
self.searchBar.delegate = self;
然后,将其设置为tableView标题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return self.searchBar;
}