[英]reload Tableview over a Button
I want to Reload my TableView with a Button Click, I read a lot of stuff, but I found just that I have to write [tableView reloadData]
the Problem is, in my own Function i dont have tableView I linked my ÌBoutlet UITableView *myTable
with the table and write the functions [myTable reloadData]
but nothing happen. 我想通过单击按钮重新加载TableView,我读了很多东西,但是我发现我必须写
[tableView reloadData]
问题是,在我自己的函数中,我没有tableView我ÌBoutlet UITableView *myTable
链接了与表并编写函数[myTable reloadData]
但没有任何反应。
in a section View i can add and delete items. 在“查看”部分中,我可以添加和删除项目。 If i change to the view with the table, they are not updated (maybe a polling updater would be better, but its the same) now i want to refresh my tableview to show the new cells
如果我更改为带有表的视图,则它们不会更新(也许轮询更新程序会更好,但还是一样),现在我想刷新表视图以显示新单元格
Do you have a good idea for me? 你对我有个好主意吗? Thanks
谢谢
EDIT: 编辑:
I wrote down in .h 我在.h中写下
IBOutlet UITableView *myTable;
@property UITableView *myTable;
in .m 在.m中
@synthesize myTable
- (IBAction)test:(id)sender
{
[self.myTableView reloadData];
}
but nothing happen if i press the Button. 但是如果我按下按钮,什么也不会发生。 I set a
NSLog
, to check the functionality in the function 我设置了
NSLog
,以检查功能中的功能
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
First put UITableView
to xib
and properly connect to outlet and create @property
in .h file and @synthesize
to .m file then use following code ( self.tableView
). 先放
UITableView
到xib
,并正确连接到插座,并创建@property
在h文件和@synthesize
到.m文件,然后使用下面的代码( self.tableView
)。
-(IBAction)btnPressed:(UIButton *) Sender
{
[self.tableView reloadData];
}
may be helpful for you :) 可能对您有帮助:)
Thanks :) 谢谢 :)
First you check that the link to that variable is still persisted. 首先,您检查到该变量的链接是否仍然存在。 If link is OK then just call
如果链接正常,请致电
[self.tableview reladData];
If the link is broken, then first link the variable to the UITableView
from the xib then try to call the same as above. 如果链接断开,则首先从xib将变量链接到
UITableView
,然后尝试像上面一样调用它。
Hope this will help you. 希望这会帮助你。
You are probably using new version of Xcode that you don't need to @synthesize in your .m file when you linked your tableView to your .h file like you did in terms of @property. 您可能正在使用Xcode的新版本,当您将tableView链接到.h文件时,不需要像@property一样在.m文件中@synthesize。
Here is what's happening when you define a @property in you .h file: 在.h文件中定义@property时,将发生以下情况:
you use synthesize like this: 您可以使用以下合成方法:
@synthesize myTable; @synthesize myTable;
so use reloadData like this: 所以像这样使用reloadData:
[myTable reloadData];
you use synthesize like this: 您可以使用以下合成方法:
@synthesize myTable=_myTable; @synthesize myTable = _myTable;
so use reloadData like one of these: 因此,请使用reloadData之类的方法之一:
either [_myTable reloadData]; or [self.myTable reloadData];
And in your case (new version of Xcode without any @synthesize) you just need to write one of these if you didn't use @synthesize 在您的情况下(没有任何@synthesize的Xcode的新版本),如果您不使用@synthesize,则只需编写其中之一即可。
[_myTable reloadData];
[_myTable reloadData];
or 要么
[self.myTable reloadData];
Hope it's helpful. 希望对您有所帮助。 I don't explain how to create IBAction or use delegate because I saw you are doing it right.
我没有解释如何创建IBAction或使用委托,因为我看到您做对了。
Good luck 祝好运
Update1: some resources for Auto @synthesize feature in Xcode 4.4 and later: Update1:Xcode 4.4和更高版本中有关Auto @synthesize功能的一些资源:
http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html
XCode 4.4 Auto @Synthesize failing on an XCode 4.3 Project XCode 4.3项目上的XCode 4.4 Auto @Synthesize失败
Update2: I just saw you said it would be better to do this by pull to refresh system. Update2:我刚刚看到您说最好通过拉动刷新系统来完成此操作。 It would be better to give some detail about the app you are building like the iOS version.
最好提供有关您正在构建的应用程序(如iOS版本)的详细信息。 If it's 6.0 or later you can use the native pull to refresh method like this:
如果是6.0或更高版本,则可以使用本机pull刷新方法,如下所示:
http://www.lextech.com/2012/10/ios-6-pull-to-refresh-tutorial/ http://www.lextech.com/2012/10/ios-6-pull-to-refresh-tutorial/
Or if it is not iOS 6.0 you can always use EGOTableViewPullRefresh I've used it and it works great even with iOS 6.0 and later. 或者,如果不是iOS 6.0,则可以始终使用EGOTableViewPullRefresh(我已使用过它),即使在iOS 6.0及更高版本中,它也能很好地工作。
https://github.com/enormego/EGOTableViewPullRefresh https://github.com/enormego/EGOTableViewPullRefresh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.