美文网首页IOSiOS DeveloperiOS学习笔记
iOS UISearchBar和UISearchDisplayC

iOS UISearchBar和UISearchDisplayC

作者: 天蓝色的海岸 | 来源:发表于2016-03-25 19:13 被阅读3205次

    当制作如苹果信息里面的搜索时,你可能做不到那种效果,会出现一些问题

    这里列举一些代码

    self.edgesForExtendedLayout = UIRectEdgeNone;// 这句代码的意思是不让它扩展布局,当你用UISearchBar 和UIsearchDisplayController的结合时可能会遇见覆盖状态栏的状况这时候你就需要在ViewDidLoad里面写上这句代码。

    另外需要将UISearchBar加到UISearchDisplayController上如:sedis=[[UISearchDisplayController alloc]initWithSearchBar:_searchbar2 contentsController:self];

    @interface AddFriendController (){

    UISearchDisplayController *sedis;

    UIView *b;

    }

    @property (nonatomic,strong) UIButton *serchbar;

    @property (nonatomic,strong) UITableView * mytable;

    @property (nonatomic,strong) NSMutableArray * datasours;

    @property (nonatomic,strong) UISearchBar * searchbar2;

    @end

    @implementation AddFriendController

    - (void)viewDidLoad {

    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeNone;

    self.view.backgroundColor=[UIColor whiteColor];

    ALLTITLENAME(@"添加好友")

    //    self.automaticallyAdjustsScrollViewInsets = NO;

    //添加ui

    [self AddUI];

    //添加AddBar

    [self AddBar];

    }

    -(void)AddUI

    {

    _searchbar2 =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, screen_width, 44)];

    [_searchbar2 setPlaceholder:@"使用手机号/昵称查找好友"];

    _searchbar2.delegate=self;

    _searchbar2.translucent = NO;// 让系统的searchBar变得不透明

    sedis=[[UISearchDisplayController alloc]initWithSearchBar:_searchbar2 contentsController:self];

    [self.view addSubview:_searchbar2];

    _mytable=[[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchbar2.frame), screen_width, screen_height-109)];

    _mytable.delegate=self;

    _mytable.dataSource=self;

    _mytable.keyboardDismissMode  =  UIScrollViewKeyboardDismissModeOnDrag;// 拖动tableView让键盘消失

    CLEAR_TABLE_LIN(_mytable)

    [self.view addSubview:self.mytable];

    }

    相关文章

      网友评论

        本文标题:iOS UISearchBar和UISearchDisplayC

        本文链接:https://www.haomeiwen.com/subject/pchdlttx.html