J0k3R J0k3R - 1 year ago 64
iOS Question

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

[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.

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?


I wrote down
in .h

IBOutlet UITableView *myTable;

@property UITableView *myTable;

in .m

@synthesize myTable

- (IBAction)test:(id)sender
[self.myTableView reloadData];

but nothing happen if i press the Button.
I set a
, to check the functionality in the function

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

Answer Source

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.

Here is what's happening when you define a @property in you .h file:

  1. you use synthesize like this:

    @synthesize myTable;

so use reloadData like this:

[myTable reloadData];
  1. you use synthesize like this:

    @synthesize myTable=_myTable;

so use reloadData like one of these:

either [_myTable reloadData]; or [self.myTable reloadData];
  1. Or you didn't use any @synthesize:

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

[_myTable reloadData];


[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.

Good luck

Update1: some resources for Auto @synthesize feature in Xcode 4.4 and later:


XCode 4.4 Auto @Synthesize failing on an XCode 4.3 Project

Update2: I just saw you said it would be better to do this by pull to refresh system. It would be better to give some detail about the app you are building like the iOS version. If it's 6.0 or later you can use the native pull to refresh method like this:


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.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download