0

I wrote a Refresh function to reload the tableview in iPhone app with the argument of UITableview. My question is how can I call or invoke this refresh function?

- (void)RefreshTableView:(UITableView *)tableView 
{
    if(tableView != nil){
       [tableView reloadData]; 
    }

}
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Rajeshwar
  • 1,471
  • 1
  • 12
  • 13
  • You don't need to check objects to see if they are `nil` before sending messages to them. Messages to `nil` are ignored. – Jim Apr 25 '12 at 14:31
  • 1
    I'm doing a joke iphone app in that the home page is listing the category from jokescategory table in database. I have settings to disable the category its working perfectly – Rajeshwar Apr 26 '12 at 04:38
  • I'm doing a joke app in that the home page is listing the category from jokescategory table from database. I have settings to disable the category the table updating working perfectly. But the problem is The RootView(home page) not getting reloaded. Its getting reloaded when run the app again. So How can I reload the RootView? I tried [tablView reloadData] and [self.tableView reloadData] I have two tables in DB one for category(jokescategory) and another one for joke(jokesbody). Both the table getting updated successfully but the RootView not reloaded. so how can I reload the RootView? – Rajeshwar Apr 26 '12 at 04:51
  • @Jim see my command I need your help.. – Rajeshwar Apr 26 '12 at 04:56
  • It's inappropriate for you to leave multiple comments asking individuals to help you. If you have a new problem, post a new question. Don't ask everybody you've interacted with in the past to help you. – Jim Apr 26 '12 at 16:29

3 Answers3

1

First of all rename your method like the following:

- (void)refreshTableView:(UITableView *)tableView

Then, to call that method you need to perform the following:

[self refreshTableView:yourTableview];

where self stands for the object that will receive the message. In this case self is an instance of the object that contains that method.

Now, why do you need to pass also an instance of the table view?

if you have a instance variable for that table view and you have synthesized it (@property/@synthesize pattern), you could simple do the following:

- (void)refreshTableView
{
    [[self myTable] reloadData];
}

and then invoke that method like the following:

[self refreshTableView];

Edit

As danh suggested, if you have a property (or an instance variable), you can also call directly

[[self myTable] reloadData]; // or [self.myTable reloadData];

without passing through refreshTableView.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
  • +1 for trimming it down. I would +1 it one more time (if I could) if you point out that the function is unnecessary. Replace with [self.myTable reloadData]; – danh Apr 25 '12 at 14:15
  • I'm doing a joke app in that the home page is listing the category from jokescategory table from database. I have settings to disable the category the table updating working perfectly. But the problem is The RootView(home page) not getting reloaded. Its getting reloaded when run the app again. So How can I reload the RootView? I tried [tablView reloadData] and [self.tableView reloadData] I have two tables in DB one for category(jokescategory) and another one for joke(jokesbody). Both the table getting updated successfully but the RootView not reloaded. so how can I reload the RootView? – Rajeshwar Apr 26 '12 at 04:52
  • @rajesh Could you explain better your goal? Maybe put an edit in your question and provide more code. Thank you. – Lorenzo B Apr 26 '12 at 07:35
  • @Flex_Addicted I have posted my question in following [link](http://stackoverflow.com/questions/10333897/how-can-i-reload-the-tableview-that-listed-in-rootviewcontroller-m-from-category) – Rajeshwar Apr 26 '12 at 13:00
0

If - (void)RefreshTableView:(UITableView *)tableView is in the same file then you can call it

[self RefreshTableView:aTableView]; when you want to call.

Maulik
  • 19,348
  • 14
  • 82
  • 137
  • thank you..but its throws the error aTableView not declared and also did tried tableView it also throws error – Rajeshwar Apr 26 '12 at 12:20
  • @rajesh: at where u have declared table view ? in .h or .m file ? – Maulik Apr 26 '12 at 12:22
  • @rajesh: If you want to use your table's variable at anywhere in .m file then you have to declare it in .h file (for variable's scope). – Maulik Apr 26 '12 at 12:35
  • I have posted my question in following link check and reply to me I need your help [link](http://stackoverflow.com/questions/10333897/how-can-i-reload-the-tableview-that-listed-in-rootviewcontroller-m-from-category) – Rajeshwar Apr 26 '12 at 13:04
0

from the class itself [self RefreshTableView:yourTableView];

form outside of the class [yourClassInstance RefreshTableView:yourTableView];

P.S: You should refactor your code and rename RefreshTableView: with refreshTableView:

Alex Terente
  • 12,006
  • 5
  • 51
  • 71
  • What you mean by it does not work? Do you have values in your data source array? Do you set the correct number of cells and rows? Do you display the data in the cellForRow? – Alex Terente Apr 26 '12 at 13:03