2

我正在制作一张表格,您可以在其中搜索不同的条目。搜索时它工作得很好,但现在我想通过按下按钮来加载表格视图。但是运行时:

[self.tableView reloadData];

cellForRowAtIndexPath没有被调用?!我读过许多有类似问题的人,但显然我无法理解他们对问题的解决方案。帮我 :)

我的头文件:

@protocol SearchViewControllerDelegate;

@interface SearchViewController : UIViewController <UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource> {
    id <SearchViewControllerDelegate> delegate;

    NSMutableArray *listOfItems;
    NSMutableArray *listOfItemsDynamic;
    UITableView *tableView;
    IBOutlet UISearchBar *sBar;
}

@property (nonatomic, assign) id <SearchViewControllerDelegate> delegate;
@property (nonatomic, retain) UITableView *tableView;
- (void) searchTableView:(NSString *) searchText;
- (IBAction)done:(id)sender;
- (IBAction)refresh:(id)sender;
@end

@protocol SearchViewControllerDelegate
- (void)searchViewControllerDidFinish:(SearchViewController *)controller;
@end

部分源代码:

@implementation SearchViewController

@synthesize delegate, tableView;
- (void)viewDidLoad {
    [super viewDidLoad];
    ...
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    [self searchTableView:searchText]; // Search all entries based on user input...
    [self.tableView reloadData]; // Works just fine
}

- (IBAction)refresh:(id)sender {    
    [self searchTableView:@"a"]; // Search all entries containing "a"...
    [self.tableView reloadData]; // FAILS! (cellForRowAtIndexPath not getting called...)
}

请帮助我,我对目标 c 很陌生,问题可能与代表的工作方式等有关......

4

0 回答 0