當制作如蘋果信息里面的搜索時切黔,你可能做不到那種效果漩勤,會出現(xiàn)一些問題
這里列舉一些代碼
self.edgesForExtendedLayout = UIRectEdgeNone;// 這句代碼的意思是不讓它擴展布局,當你用UISearchBar 和UIsearchDisplayController的結合時可能會遇見覆蓋狀態(tài)欄的狀況這時候你就需要在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;// 讓系統(tǒng)的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];
}