如何使表格视图重新显示

发布于 2024-08-05 10:28:37 字数 761 浏览 1 评论 0原文

我有一个导航 iPhone 应用程序,它的“第二级”控制器当前是一个 UIViewController,其 Nib 包含一个 UIView。我在 UIView 的顶部留出空间作为导航栏,然后在底部添加一个工具栏,在上面放置一个刷新按钮、一个标签和一个活动指示器。最后但并非最不重要的一点是,我在中间放置了一个表视图。

我将控制器和笔尖之间的所有内容连接起来,并使文件的所有者连接到 UIView 和 UIView 包含的 UITableView 的数据源和委托,以引用文件的所有者,一切正常。

但我不知道如何告诉表视图刷新。

我想我可以将其放在我想要更新表的代码中:

[self.tableView reloadData];

但是除非我的第二级控制器是 UITableViewController,否则该行代码将无法编译。当我将第二级控制器设为 UITableViewController 时,加载第二级控制器时我的应用程序会崩溃,因为文件的所有者不引用表视图控制器,并且当我使文件的所有者引用表视图出口而不是视图,除了底部的工具栏及其标签和刷新按钮不再出现之外,一切正常。

我还尝试简单地添加代替

[self refresh];

[self.tableview reloadData] 但代码陷入了刷新自身的循环中。

我怎样才能让这一切正常工作?我认为我需要将第二级控制器保留为 UIViewcontroller,但我仍然希望能够在需要时获取它包含的 UITableView 进行自我更新。

I've got a Navigation iPhone app and it's "second level" controller is currently a UIViewController whose Nib contains a UIView. I made space at the top of the UIView for a navigation bar and then I added a tool bar on the bottom, on which I put a refresh button, a label, and an activity indicator. Last, but not least, I put a table view in the middle.

I connected everything up between the controller and the nib and made the File's owner connect to the UIView and the datasource and delegate for the UITableView contained by the UIView to refer to the File's owner and everything works fine.

But I can't figure out how to tell the table view to refresh.

I thought I could just put this in the code where I want the table to update:

[self.tableView reloadData];

But unless my second level controller is a UITableViewController that line of code won't compile. When I make my second level controller a UITableViewController, my app blows up when the second level controller gets loaded because the file's owner doesn't refer to a table view controller, and when I make the file's owner refer to the table view outlet instead of the view, things work except for the fact my tool bar on the bottom, along with its label and refresh button don't appear anymore.

I also tried simply adding

[self refresh];

in place of [self.tableview reloadData] but the code gets stuck in a loop refreshing itself.

How can I get this all working? I think I need to leave my second level controller as a UIViewcontroller but I still want to be able to get the UITableView it contains to update itself when I want it to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-08-12 10:28:37

为什么你的二级控制器不能是 UITableViewController?首先,它是 UIViewController 的子类,因此您不会丢失任何功能。

无论如何,非 UITableViewController UIViewController 类没有可以调用的 tableView 属性。相反,您应该保留自己的 ivar 中的表视图并调用它。 (您甚至可以将其称为 tableView;您只需自己定义它即可。)

@interface MyViewController : UIViewController {
    UITableView *tableView;
}

@property(nonatomic,retain) IBOutlet UITableView *tableView;

- (void)myMethod;

@end
@implementation MyViewController

@synthesize tableView;

- (void)myMethod {
    [self.tableView reloadData];
}

Why can't your second-level controller be a UITableViewController? It's a subclass of UIViewController to begin with, so you're not losing any functionality.

In any event, non-UITableViewController UIViewController classes don't have the tableView property you can call. You should instead hold on to the table view in your own ivar and call that. (You can even call it tableView; you just have to define it yourself.)

@interface MyViewController : UIViewController {
    UITableView *tableView;
}

@property(nonatomic,retain) IBOutlet UITableView *tableView;

- (void)myMethod;

@end
@implementation MyViewController

@synthesize tableView;

- (void)myMethod {
    [self.tableView reloadData];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文