如何在当前视图控制器中重新加载另一个uiviewcontroller的tableview

发布于 2024-11-30 16:17:21 字数 99 浏览 2 评论 0原文

请帮帮我。如果它重复,我感到非常抱歉,但我没有得到所需的答案,这就是我再次询问的原因。
我想在第一个视图中重新加载另一个视图的表。

提前致谢。

Please help me out. I am very sorry if it is duplicate but i didn't get required answer that is why i am asking again.
I want to reload table of anotherview in my first view.

Thanks in adavance.

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

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

发布评论

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

评论(4

绿萝 2024-12-07 16:17:21

在第一个 viewcontroller.m 中,我将其放入 viewDidLoad 方法中:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle_data) name:@"reload_data" object:nil];

    -(void)handle_data {
        [yourtableview reloaddata];
    }

在第二个 viewcontroller.m 中:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];

In the first viewcontroller.m, I put this in the viewDidLoad method:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle_data) name:@"reload_data" object:nil];

    -(void)handle_data {
        [yourtableview reloaddata];
    }

In the second viewcontroller.m:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];
爱的故事 2024-12-07 16:17:21
  1. 使用nonatomicretainUITableview创建属性..(视图控制器1)

  2. 在视图控制器 2 中创建视图控制器 1 的对象。

  3. 现在在 viewcontroller 1 对象的帮助下您可以访问它。

示例

在 ViewController2 .m 文件中:

ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....];   

[objV1.yourTableView reloadData];
  1. Create property for UITableview with nonatomic and retain.. (view controller 1)

  2. in View Controller 2 create object of viewcontroller 1.

  3. now with help of viewcontroller 1 object you can access it.

Example:

In ViewController2 .m file:

ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....];   

[objV1.yourTableView reloadData];
寄居者 2024-12-07 16:17:21

按以下方式执行:

假设您有 2 个视图控制器。

  • ViewController1

  • ViewController2

并且您在 ViewController2 中有 UITableView 对象 tblTable

ViewController2.h 文件中:

@property(nonatomic, retain) UITableView *tblTable;

ViewController2.m 文件中:

@synthesize tblTable;

现在在 ViewController1.m 文件中:

ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....];

[objV1.tblTable reloadData];

我希望它对您有所帮助。

如有任何困难请告诉我。

干杯。

Do it in below way:

Suppose you have 2 view controller.

  • ViewController1

  • ViewController2

And you have UITableView object tblTable in ViewController2.

in ViewController2.h file:

@property(nonatomic, retain) UITableView *tblTable;

in ViewController2.m file:

@synthesize tblTable;

Now in in ViewController1.m file:

ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....];

[objV1.tblTable reloadData];

I hope it will be helpful to you.

Let me know in case of any difficulty.

Cheers.

琉璃繁缕 2024-12-07 16:17:21

我有类似的问题,我正在使用故事板,这就是我解决它的方法。假设您想从 ViewController1 中的函数重新加载 ViewController2 中的表。执行以下操作:

 #import "ViewController2.h"

现在将此代码放入您想要重新加载的函数或任何按钮操作中

ViewController2 *ob= (ViewController2*)[self.navigationController topViewController];
    [ob.viewController2Table reloadData];

I had similar issue and I was using storyboard this is how I fixed it. Suppose u want to reload the table which is in ViewController2 from a function in ViewController1. Do the following:

 #import "ViewController2.h"

Now put this code in the function or any button action under which u want to reload

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