cellForRowAtIndexPath 有时不会被 reloadData 调用?
我正在制作一个表格,您可以在其中搜索不同的条目。当您搜索时它工作得很好,但现在我想通过按按钮加载表格视图。但是运行时:
[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...)
}
请帮助我,我对 Objective C 很陌生,问题可能与代表的工作方式等有关......
I'm making a table which you can search for different entries. It works just fine when you search but now I want to load the tableview by pressing a button. But when running:
[self.tableView reloadData];
cellForRowAtIndexPath is not getting called?! I've read numerous of people having similar problems but clearly I don't manage to understand their solution to the problem. Help me :)
My header file:
@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
Some of the source code:
@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...)
}
Please help me, I'm quite new to objective c and the problem is probably related to how delegates works etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论