如何在当前viewcontroller中重新加载另一个uiviewcontroller的tableview

时间:2011-08-20 07:02:25

标签: ios iphone objective-c uitableview viewcontroller

请帮帮我。我很抱歉,如果它是重复但我没有得到必要的答案,这就是为什么我再次要求 我想在第一个视图中重新加载另一个视图的表。

谢谢你。

4 个答案:

答案 0 :(得分:12)

在第一个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];

答案 1 :(得分:3)

  1. 使用UITableviewnonatomicretain创建属性..(查看控制器1)

  2. View Controller 2中的
  3. 创建了viewcontroller 1的对象。

  4. 现在借助viewcontroller 1对象可以访问它。

  5. 示例

    在ViewController2 .m文件中:

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

答案 2 :(得分:1)

以下面的方式做到:

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

  • ViewController1

  • ViewController2

您在UITableView中有tblTable个对象ViewController2

<{1>}文件中的

ViewController2.h
<{1>}文件中的

@property(nonatomic, retain) UITableView *tblTable;

现在位于ViewController2.m档案中:

@synthesize tblTable;

我希望它会对你有所帮助。

如有任何困难,请告诉我。

干杯。

答案 3 :(得分:0)

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

 #import "ViewController2.h"

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

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