xcode 从导航控制器重新加载 tableview

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5267110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:26:41  来源:igfitidea点击:

reload tableview from navigation controller

iphoneobjective-cxcodeuitableviewuinavigationcontroller

提问by Neelesh

I am new to iPhone development.

我是 iPhone 开发的新手。

I have a navigation controller which loads a tableview. The class identity of the tableview is a tableViewController class.

我有一个加载 tableview 的导航控制器。tableview 的类标识是 tableViewController 类。

I want to know how to refresh the table view from the navigation controller.

我想知道如何从导航控制器刷新表视图。

I know within the tableViewController i can use the

我知道在 tableViewController 中我可以使用

[self.tableView reloadData];

Sorry if i am vague. Thanks in advance.

对不起,如果我含糊不清。提前致谢。

after feedback:

反馈后:

Here is the navigation controller

这是导航控制器

@interface slNavController : UINavigationController{

UIToolbar *toolbar;
slTableViewController *tableVC;

}
@property(nonatomic, retain) slTableViewController *tableVC;

where slTableViewController is the Delegate of the tableView that needs to be refreshed.

其中 slTableViewController 是需要刷新的 tableView 的 Delegate。

and where i needed to refresh the table i used

我需要在哪里刷新我使用的表格

[tableVC.tableView reloadData];

Here is slTableViewController header

这是 slTableViewController 标头

@interface slTableViewController : UITableViewController <UITableViewDelegate,UITableViewDataSource> {

IBOutlet UITableView *slTableView;
NSMutableArray *list;
TryAppDelegate *appDelegate;
//UIToolbar *toolbar;
IBOutlet UITextField *textField;

}

But still not able to refresh the tableview.

但仍然无法刷新tableview。

采纳答案by PengOne

There must be some viewController which is the delegate of the tableView. Send reloadData to that controller, e.g.

必须有一些 viewController 是 tableView 的委托。将 reloadData 发送到该控制器,例如

[viewController.tableView reloadData];

If you know where in the stack the viewController is, you can access it through the navController. For instance, if it happens to be the rootViewController, then you can do

如果您知道 viewController 在堆栈中的位置,您可以通过 navController 访问它。例如,如果它恰好是 rootViewController,那么你可以这样做

HomesViewController *homesController = [[[self navigationController] viewControllers] objectAtIndex:0];

HomesViewController *homesController = [[[self navigationController] viewControllers] objectAtIndex:0];

回答by prasanna

If it is Navigation based application you want to reload the data of table view, You have to write in view will appear like this

如果是基于导航的应用程序,您想重新加载表格视图的数据,您必须在视图中写入会出现这样的

[self.tableView reloadData];

回答by GendoIkari

Give your navigationController a pointer to the tableViewController.

给你的 navigationController 一个指向 tableViewController 的指针。

In the .h file:

在 .h 文件中:

@property(nonatomic, retain) YourTableViewController *tableViewController;

Then when you want to reload data:

然后当你想重新加载数据时:

[tableViewController.tableView reloadData];