[英]how to reload tableview of another uiviewcontroller in current viewcontroller
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. 谢谢,谢谢。
In the first viewcontroller.m, I put this in the viewDidLoad
method: 在第一个viewcontroller.m中,我把它放在
viewDidLoad
方法中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle_data) name:@"reload_data" object:nil];
-(void)handle_data {
[yourtableview reloaddata];
}
In the second viewcontroller.m: 在第二个viewcontroller.m中:
[[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];
Create property for UITableview
with nonatomic
and retain
.. (view controller 1) 使用
nonatomic
为UITableview
创建属性并retain
..(查看控制器1)
in View Controller 2 create object of viewcontroller 1. 在View Controller 2中创建viewcontroller 1的对象。
now with help of viewcontroller 1 object you can access it. 现在借助viewcontroller 1对象可以访问它。
Example : 示例 :
In ViewController2 .m file: 在ViewController2 .m文件中:
ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....];
[objV1.yourTableView reloadData];
Do it in below way: 以下面的方式做:
Suppose you have 2 view controller. 假设您有2个视图控制器。
ViewController1 ViewController1
ViewController2 ViewController2
And you have UITableView
object tblTable
in ViewController2
. 并且你在
ViewController2
有UITableView
对象tblTable
。
in ViewController2.h
file: 在
ViewController2.h
文件中:
@property(nonatomic, retain) UITableView *tblTable;
in ViewController2.m
file: 在
ViewController2.m
文件中:
@synthesize tblTable;
Now in in ViewController1.m
file: 现在在
ViewController1.m
文件中:
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. 干杯。
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.
假设您想从ViewController1中的函数重新加载ViewController2中的表。 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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.