0

当应用程序在模拟器中运行时,披露指示器不显示。因此,我无法转到详细信息

名称TableViewController.m:

#import "NamesTableViewController.h"

@interface NamesTableViewController ()
@property (nonatomic, copy) NSDictionary *propertyList;
@property (nonatomic, copy) NSArray *letters;
@property (nonatomic, copy)NSMutableArray *filteredNames;
@property (nonatomic, strong)UISearchController *searchController;


@end

@implementation NamesTableViewController

@synthesize propertyList,  letters, filteredNames, searchController;

- (void)viewDidLoad {
    [super viewDidLoad];

    UITableView *tableView = (id)[self.view viewWithTag:1];

    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

    filteredNames = [[NSMutableArray alloc]init];
    searchController = [[UISearchController alloc]init];

    //bura bax self yigishdir
    self.searchController.searchResultsUpdater = self;

    NSString *path = [[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"];
    self.propertyList = [NSDictionary dictionaryWithContentsOfFile:path];
    self.letters = [[self.propertyList allKeys] sortedArrayUsingSelector:@selector(compare:)];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView.tag == 1){

        return self.letters.count;

    }else {
        return 1;
    }

    }

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

    if (tableView.tag == 1) {

        NSString *letter = self.letters[section];
        NSArray *keyValues = [self.propertyList[letter] allKeys];
        return keyValues.count;
    } else {


        return [filteredNames count];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    if (tableView.tag == 1){

        NSString *letter = self.letters[indexPath.section];;
        NSArray *keyValues = [[self.propertyList[letter] allKeys] sortedArrayUsingSelector:@selector(compare:)];
        cell.textLabel.text = keyValues[indexPath.row];
    } else{
        cell.textLabel.text = filteredNames[indexPath.row];
    }
    return cell;
}

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return self.letters;
}

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if (tableView.tag == 1) {
        return letters [section];
    } else {
        return nil;
    }
}

#pragma mark Search Display Delegate Methods

-(void)searchDisplayController:(UISearchController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}



-(BOOL)searchDisplayController:(UISearchController *)controller shouldReloadTableForSearchString:(NSString *)searchString

{

    [filteredNames removeAllObjects];
    if (searchString.length > 0) {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [search] %@", self.searchBar.text];

        for (NSString *letter in letters) {
            NSArray *matches = [[self.propertyList[letter] allKeys]filteredArrayUsingPredicate:predicate];

            [filteredNames addObjectsFromArray:matches];

        }

    }

    return YES;
}


@end

名称TableViewController.h:

#import <UIKit/UIKit.h>


@interface NamesTableViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>


@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;

@end

我怎样才能做到这一点?请帮助我。我是新的

4

1 回答 1

1

试试这个

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    .......
}

更新

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here, for example: If your are used in connection 
// use this

   [self performSegueWithIdentifier:@"yourSegueName" sender:self];

 // if you are used connection less in storyboard , use this
 DetailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
   // Push the view controller.
[self.navigationController pushViewController:vc animated:YES];


}
于 2016-02-15T07:52:16.023 回答