iosiOS 10开发中经常遇到的问题总结
来源:互联网 发布:数据挖掘入门 编辑:程序博客网 时间:2024/05/01 13:22
1.如何手动取消UIDispalaySearchController的取消搜索状态- #pragma mark UISearchDisplayDelegate
- - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
- {
- for (UIView *view in controller.searchBar.subviews)
- {
- NSLog(@"%d__|---%@",__LINE__,view);
- for (UIView *subView in view.subviews)
- {
- NSLog(@"%d__|!!!%@",__LINE__,subView);
- // 获取"取消"按钮
- if([subView isKindOfClass:[UIButton class]])
- {
- UIButton *cancelButton = (UIButton *)subView;
- // 获取点击"取消"按钮的响应事件(actionsForTarget 这个方法返回的是一个数组)
- self.cancelSearchSELString = [[cancelButton actionsForTarget:controller.searchBar forControlEvent:UIControlEventTouchUpInside] objectAtIndex:0];
- // 响应通知,执行方法直接用上面获得的响应事件方法,转换一下(这是个知识点,可以扩展下)
- [[NSNotificationCenter defaultCenter] addObserver:controller.searchBar selector:NSSelectorFromString(self.cancelSearchSELString) name:@"cancelSearch" object:nil];
- }
- }
- }
- }
-
- #pragma mark UISearchBarDelegate------点击搜索按钮
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
-
- // 获取你想搜索的最终完整关键字(一般可以用来做搜索历史展示)
- NSLog(@"%s__%d__|%@",__FUNCTION__,__LINE__,searchBar.text);
- // 点击按钮时,发布取消搜索状态通知
- [[NSNotificationCenter defaultCenter] postNotificationName:@"cancelSearch" object:nil];
- // 发布---响应---取消通知
- [[NSNotificationCenter defaultCenter] removeObserver:searchBar name:@"cancelSearch" object:nil];
- }
- 2.如何知道导航栏是pop还是push
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- if ([self isMovingFromParentViewController])
- {
- NSLog(@"View controller was popped");
- }
- else
- {
- NSLog(@"New view controller was pushed");
- }
- }
- 3.更改导航栏颜色
- if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
-
- // do stuff for iOS 7 and newer
- [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
- }
- else {
-
- // do stuff for older versions than iOS 7
- [self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
- }
- 4.如何更改导航栏title文字的颜色
- [self.navigationController.navigationBar setTitleTextAttributes:
- @{NSForegroundColorAttributeName:[UIColor redColor],
- NSFontAttributeName:[UIFont fontWithName:@"mplus-1c-regular" size:21]}];
- 5.减少多余的tableView空的cell
- tableView.tableFooterView = [UIView new];
6.返回CGFloat_MIN
- // footer 间距
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- // return 1.0f;
- return CGFLOAT_MIN;
- }
- 7.减少默认tableView的sectionHeader和Footer的高度,直接设置0是无效的,最小是1.0f
- - (CGFloat)tableView:(UITableView*)tableView
- heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 6.0;
- }
-
- return 1.0;
- }
-
- - (CGFloat)tableView:(UITableView*)tableView
- heightForFooterInSection:(NSInteger)section {
- return 5.0;
- }
-
- - (UIView*)tableView:(UITableView*)tableView
- viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] initWithFrame:CGRectZero];
- }
-
- - (UIView*)tableView:(UITableView*)tableView
- viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] initWithFrame:CGRectZero];
- }
- 8.设置中号字体
- UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:14.0f];
- //iOS8.2开始
- [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
-
0 0