2013-04-10 4 views
0
  1. JASidePanel - https://github.com/gotosleep/JASidePanels을 사용하여 메뉴 효과를 만듭니다.
  2. xib와 협력하고 있습니다.
  3. 내 수업은 UIViewController를 확장합니다.
  4. 다른 테이블에 표시하는 방법을 모르겠다. searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText:
  5. 첫 번째 tableView는 Panel이고 필터링 된 것은 이름이있는 Thumb입니다.
  6. 다음 코드는 두 번째 tableview 추가해야 할 때 중지됩니다.

SidePanelViewController.h동일한 UIViewController에서 두 TableView에 UISearchBar를 추가하는 방법

@interface SidePanelViewController : UIViewController <UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate> 
{ 
    IBOutlet UIImageView *_photoProfile; 
    IBOutlet UILabel *_nameLabel; 
    NSArray *_menuArray; 
} 

@property (nonatomic, readonly) IBOutlet UISearchBar *searchBar; 
@property (nonatomic, strong) IBOutlet UITableView *tableView; 
@property(nonatomic, strong) NSMutableArray *tableViewData; 
@property(nonatomic, strong) NSMutableArray *originalTableViewData; 
@property(nonatomic, strong) NSMutableArray *searchArray; 
@property(nonatomic, strong) NSMutableDictionary *units; 

SidePanelViewController.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 


    // Do any additional setup after loading the view from its nib. 
    _menuArray = [[NSArray alloc]initWithObjects:@"Home",@"Meu QR Sem Hora", @"Favoritas", @"Minha Pontuação", @"Minha Conta",@"Convidar Amigos", @"Ajuda", @"Fale Conosco",@"Privacidade e Termos", nil]; 

    _tableViewData = [[NSMutableArray alloc] initWithArray:_menuArray]; 
    // Don't show the scope bar or cancel button until editing begins 
    [_searchBar setShowsScopeBar:NO]; 
    [_searchBar sizeToFit]; 

    // 
    // Create a header view. Wrap it in a container to allow us to position 
    // it better. 
    // 
    UIView *containerView = 
    [[UIView alloc] 
    initWithFrame:CGRectMake(0, 0, 320, 30)]; 
    UILabel *headerLabel = 
    [[UILabel alloc] 
    initWithFrame:CGRectMake(0, 0, 320, 30)]; 
    headerLabel.text = NSLocalizedString(@"Perfil", @""); 
    headerLabel.textColor = [UIColor blackColor]; 
    headerLabel.shadowColor = [UIColor whiteColor]; 
    headerLabel.shadowOffset = CGSizeMake(0, 1); 
    headerLabel.font = [UIFont boldSystemFontOfSize:22]; 
    headerLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 
    [containerView addSubview:headerLabel]; 
    self.tableView.tableHeaderView = containerView; 

    //SetName and Picture 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    _nameLabel.text = [defaults valueForKey:@"name"]; 
    _photoProfile.image = [UIImage imageWithData:[defaults objectForKey:@"Photo"]]; 

} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [_tableView reloadData]; 
} 

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 
    [self filterContentForSearchText:searchText]; 
} 

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 
{ 
    [self.sidePanelController setCenterPanelHidden:YES animated:YES duration:0.2f]; 
} 

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar 
{ 
    [self.sidePanelController setCenterPanelHidden:NO animated:YES duration:0.2f]; 
     searchBar.text = @""; 
    _tableViewData = [_originalTableViewData mutableCopy]; 
    [_tableView reloadData]; 
    [searchBar resignFirstResponder]; 

} 

- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller 
{ 
    [self.sidePanelController setCenterPanelHidden:NO animated:YES duration:0.2f]; 
} 

#pragma mark - ScrollView (UITableView) delegate methods 
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
    [_searchBar resignFirstResponder]; 
    [self performSelector:@selector(enableCancelButton:) withObject:self.searchBar afterDelay:0.0]; 
} 

// Used to re-enabled the cancel button when a user starts scrolling 
- (void)enableCancelButton:(UISearchBar *)aSearchBar { 
    for (id subview in [aSearchBar subviews]) { 
     if ([subview isKindOfClass:[UIButton class]]) { 
      [subview setEnabled:TRUE]; 
     } 
    } 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)filterContentForSearchText:(NSString *)searchText { 
    if (searchText && searchText.length) { 
     [_tableViewData removeAllObjects]; 

     for (NSDictionary *dictionary in _originalTableViewData) 
     { 
      for (NSString *thisKey in [dictionary allKeys]) { 
       if ([thisKey isEqualToString:@"SearchKey1"] || 
        [thisKey isEqualToString:@"SearchKey2"]) { 

        if ([[dictionary valueForKey:thisKey] rangeOfString:searchText 
                   options:NSCaseInsensitiveSearch].location != NSNotFound) { 
         [_tableViewData addObject:dictionary]; 
        } // for (NSString *thisKey in allKeys) 

       } // if ([thisKey isEqualToString:@"SearchKey1"] || ... 
      } // for (NSString *thisKey in [dictionary allKeys]) 
     } // for (NSDictionary *dictionary in originalTableViewData) 

     [_tableView reloadData]; 

    } // if (query && query.length) 
} 

#pragma mark - UITableViewDelegate 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    return _menuArray.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIndentifier = @"CustomMenu"; 

    CustomMenuCell *cell = (CustomMenuCell *) [_tableView dequeueReusableCellWithIdentifier:cellIndentifier]; 


    if(!cell){ 

     cell = (CustomMenuCell *) [[[NSBundle mainBundle] loadNibNamed:@"CustomMenuView" owner:nil options:nil] objectAtIndex:0]; 
    } 

    NSString *tempString = [_menuArray objectAtIndex:indexPath.row]; 
    [cell configureMenu:tempString]; 


    cell.selectionStyle = UITableViewCellSelectionStyleGray; 

    return cell; 
} 

enter image description hereenter image description here

답변

0

당신이 해결 여부를 알고,하지만하지 마십시오 네 말 뜻은 다른 테이블보기로 보여? 게시 한 두 번째 이미지와 비슷한 것으로 표시된다면 "검색 창 및 검색 표시"를 사용하는 경우 검색 표시 줄에 이미 있어야한다고 말할 수 있습니까? 당신이 검색 창 및 디스플레이 것을 사용 않은 경우

self.searchDisplayController.searchResultsTableView

, 당신은 자 NSPredicate를 복사하고이 당신의 originalTableViewData에서 입각하는 필터 변경 가능한 배열을 만들 수 있습니다. 이 정보가 도움이되기를 바랍니다.

+0

나는이 작업을 이미했고 많은 작업을해야하며, 문제는 테이블 뷰를 변경하고, 새로운 행 수를 확인하고, 새 콘텐츠로 채우고, 필터를 만들고, 검색이 집중 가능한지 확인해야한다는 것입니다. 'X'버튼을 클릭하여보기를 지우십시오. – Marckaraujo

관련 문제