我正在制作一张表,您可以搜索不同的条目。搜索时它工作正常,但现在我想通过按下按钮加载tableview。但是在跑步时:
[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很新,问题可能与代表的工作方式有关......