IOS 10开发中经常遇到的问题总结。
1.如何手动取消UIDispalaySearchController的取消搜索状态
#pragmamarkUISearchDisplayDelegate
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController*)controller
{
for(UIView*viewincontroller.searchBar.subviews)
{
NSLog(@"%d__|---%@",__LINE__,view);
for(UIView*subViewinview.subviews)
{
NSLog(@"%d__|!!!%@",__LINE__,subView);
//获取"取消"按钮
if([subViewisKindOfClass:[UIButtonclass]])
{
UIButton*cancelButton=(UIButton*)subView;
//获取点击"取消"按钮的响应事件(actionsForTarget这个方法返回的是一个数组)
self.cancelSearchSELString=[[cancelButtonactionsForTarget:controller.searchBarforControlEvent:UIControlEventTouchUpInside]objectAtIndex:0];
//响应通知,执行方法直接用上面获得的响应事件方法,转换一下(这是个知识点,可以扩展下)
[[NSNotificationCenterdefaultCenter]addObserver:controller.searchBarselector:NSSelectorFromString(self.cancelSearchSELString)name:@"cancelSearch"object:nil];
}
}
}
}
#pragmamarkUISearchBarDelegate------点击搜索按钮
-(void)searchBarSearchButtonClicked:(UISearchBar*)searchBar{
//获取你想搜索的最终完整关键字(一般可以用来做搜索历史展示)
NSLog(@"%s__%d__|%@",__FUNCTION__,__LINE__,searchBar.text);
//点击按钮时,发布取消搜索状态通知
[[NSNotificationCenterdefaultCenter]postNotificationName:@"cancelSearch"object:nil];
//发布---响应---取消通知
[[NSNotificationCenterdefaultCenter]removeObserver:searchBarname:@"cancelSearch"object:nil];
}
2.如何知道导航栏是pop还是push
-(void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
if([selfisMovingFromParentViewController])
{
NSLog(@"Viewcontrollerwaspopped");
}
else
{
NSLog(@"Newviewcontrollerwaspushed");
}
}
3.更改导航栏颜色
if(NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1){
//dostuffforiOS7andnewer
[self.navigationController.navigationBarsetBarTintColor:[UIColoryellowColor]];
}
else{
//dostuffforolderversionsthaniOS7
[self.navigationController.navigationBarsetTintColor:[UIColoryellowColor]];
}
4.如何更改导航栏title文字的颜色
[self.navigationController.navigationBarsetTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColorredColor],
NSFontAttributeName:[UIFontfontWithName:@"mplus-1c-regular"size:21]}];
5.减少多余的tableView空的cell
tableView.tableFooterView= [UIView new];
6.返回CGFloat_MIN
//footer间距
-(CGFloat)tableView:(UITableView*)tableViewheightForFooterInSection:(NSInteger)section
{
//return1.0f;
returnCGFLOAT_MIN;
}
7.减少默认tableView的sectionHeader和Footer的高度,直接设置0是无效的,最小是1.0f
-(CGFloat)tableView:(UITableView*)tableView
heightForHeaderInSection:(NSInteger)section{
if(section==0){
return6.0;
}
return1.0;
}
-(CGFloat)tableView:(UITableView*)tableView
heightForFooterInSection:(NSInteger)section{
return5.0;
}
-(UIView*)tableView:(UITableView*)tableView
viewForHeaderInSection:(NSInteger)section{
return[[UIViewalloc]initWithFrame:CGRectZero];
}
-(UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section{
return[[UIViewalloc]initWithFrame:CGRectZero];
}
8.设置中号字体
UIFont*font=[UIFontfontWithName:@"HelveticaNeue-Medium"size:14.0f];
//iOS8.2开始
[UIFontsystemFontOfSize:14weight:UIFontWeightMedium];
就爱阅读www.92to.com网友整理上传,为您提供最全的知识大全,期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/02-21/17363208.html