添加UISearchBar的方法

来源:互联网 发布:xp自动修复软件 编辑:程序博客网 时间:2024/06/05 10:08

代码

  1. UISearchBar *mySearchBar = [[UISearchBar alloc] 
  2. initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];          
  3.  mySearchBar.delegate = self;          
  4.  mySearchBar.showsCancelButton = NO;          
  5.  mySearchBar.barStyle=UIBarStyleDefault;          
  6.  mySearchBar.placeholder=@"Enter Name or Categary";           
  7. mySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;           
  8. [self.view addSubview:mySearchBar];          
  9.  [mySearchBar release];    

在 tableview上添加:   

代码  

  1. //add Table  
  2.         UITableView *myBeaconsTableView = [[UITableView alloc]   
  3.                                            initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-40)    
  4.   style:UITableViewStylePlain];  
  5.         myBeaconsTableView.backgroundColor = [UIColor whiteColor];  
  6.         myBeaconsTableView.delegate=self;  
  7.         myBeaconsTableView.dataSource=self;  
  8.         [myBeaconsTableView setRowHeight:40];  
  9.         // Add searchbar   
  10.         searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40)];  
  11.         searchBar.placeholder=@"Enter Name";  
  12.         searchBar.delegate = self;  
  13.         myBeaconsTableView.tableHeaderView = searchBar;  
  14.         searchBar.autocorrectionType = UITextAutocorrectionTypeNo;  
  15.         searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;  
  16.         [searchBar release];  
  17.         [self.view addSubview:myBeaconsTableView];  
  18.         [myBeaconsTableView release];  
原创粉丝点击