cellForRowAtIndexPath 有时不会被 reloadData 调用?

发布于 2024-11-30 19:43:29 字数 1636 浏览 1 评论 0原文

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

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文