UISearchDisplayController c UITableView (не UITableViewController)

Рейтинг: 0Ответов: 2Опубликовано: 27.02.2015

Друзья, подскажите по: Поиск в TableView.

  • Создал программно UISearchBar и UISearchDisplayController.
  • Подписался на их делегаты.
  • Создал новый массив resultSearch (мутабельный)

и т.д.

В общем, суть такова, что во всех примерах, которых я нашел, TableView там выступает как TableViewController, У меня наоборот - обычный контроллер, на котором лежит TableView.

Немогу понять, куда мне указывать в:

_srchDisplayController.searchResultsDelegate = ?;
_srchDisplayController.searchResultsDataSource = ?;

Если в примерах self = UITableViewController., а у меня получается, что это просто ViewController и он, естественно, ничего не даст. Как связать с таблицей?

UPD:

@interface ContactTable () <UITableViewDelegate,
                            UITableViewDataSource,
                            UISearchDisplayDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *contactArray;
@property (strong, nonatomic) NSMutableArray *arrSearchContacts;
@property (strong, nonatomic) UISearchDisplayController *srchDisplayController;
@property (strong, nonatomic) UISearchBar *srchContact;

@end

@implementation ContactTable

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title = @"Список контактов";

    [self loadContacts];

    _tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    _tableView.delegate = self;
    _tableView.dataSource = self;

    _srchContact = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 64)];
    _srchContact.autocorrectionType = UITextAutocorrectionTypeNo;
    _srchContact.searchBarStyle = UISearchBarStyleDefault;
    _srchContact.barTintColor = uBlueSearchBarColor;
    _srchContact.tintColor = [UIColor whiteColor];
    _srchContact.translucent = YES;
    _srchContact.placeholder = @"Поиск";
    _srchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_srchContact
                                                               contentsController:self];
    _srchDisplayController.delegate = self;
    _srchDisplayController.searchResultsDelegate = self;
    _srchDisplayController.searchResultsDataSource = self;

    [_tableView setTableHeaderView:_srchContact];
    [self.view addSubview:_tableView];

    _arrSearchContacts = [NSMutableArray arrayWithCapacity:_contactArray.count];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];

    self.navigationItem.title = @"Список контактов";
}

- (void) loadContacts
{
    [NETWORKING makeRequest:Contacts
                 loginBlock:nil
              userDataBlock:nil
              projectsBlock:nil
               contactBlock:^(NSArray *contacts){
                   _contactArray = contacts;
                   dispatch_async(dispatch_get_main_queue(), ^{
                       [_tableView reloadData];
                   });
               }
           projectsTimeShit:nil];
}

#pragma mark - UITableview Delegates & DataSource methods

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

    if (_tableView == _srchDisplayController.searchResultsTableView) {

        return _arrSearchContacts.count;

    } else {

        return _contactArray.count;
    }

}

Ответы

Ответов пока нет.