当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS 10开发中经常遇到的问题总结

IOS 10开发中经常遇到的问题总结

2018年11月01日  | 移动技术网移动技术  | 我要评论

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(@"viewcontrollerwopped");

}

else

{

nslog(@"newviewcontrollerwaspushed");

}

}

3.更改导航栏颜色

if(nsfoundationversionnumber>nsfoundationversionnumber_ios_6_1){

//tuffforios7andnewer

[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];


如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网