Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Refresh tableview not working

merou1990merou1990 francePosts: 14New Users *
I am new in objective-c developpment, I need to find a way to refresh my tableview.

I have 2 UIViewControllers, in the second one I insert data into my database and then I instantiate the first viewcontroller, it contains my tableview. I call a method that allows it to recover all of the data from the database, but when I use [tableview reloadData] nothing happens and cellforrowatindexpath isn't called.

secondviewcontroller: //I insert data in database and I instanciate class where my tableview is and call refresh method

first = [[FirstviewController alloc]initWithNibName:@FirstviewController bundle:nil];

[first refreshList];

in Firstviewcontroller

-(void)refreshList{

self.tableview= [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
tableview.dataSource = self;
tableview.delegate = self;

NSMutableArray *array = [[NSMutableArray alloc] init];
//I recover my data from data base

IPADAGRIONEActivityList *arrayActivities = [IPADAGRIONEActivity findAll];

if ([arrayActivities length] > 0)
{
for (IPADAGRIONEActivity * oneRec in arrayActivities)
{
[array addObject:oneRec];


}
}
//activities is NSMutablearray that contains all my data
self.activities = array;

//I build dictionnary
[self buildObjectsDictionnary:activities

NSLog(@self.act%@",self.tableview);
[array release];
[self.tableview reloadData];
}

//numberofrowsinSection:

NSLog(@rows%d,objects objectForKey:[objectsIndex objectAtIndex:section count]);
return objects objectForKey:[objectsIndex objectAtIndex:section ;

//numberOfSection:

NSLog(@nbre of section%d,[objectsIndex count]);
return [objectsIndex count];}

//CellforRowatInddexPath: It dosen't access to this method

if (cell== nil) {
cell = [[MHCActivityListCell alloc]init];
}

IPADAGRIONEActivity *activite;

cell.activityCategory.text = [NSString stringWithFormat:@%@", [activite EMAIL]];

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,676Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    See the thread at the top about making your code look nice.

    Instantiate and alloc mean "create" or "build". This means that anytime you do this, the end result is something new.

    Presumably, you started with FirstViewController, and then you went to SecondViewController. So if you alloc FirstViewController from there, this means you will have a total of 2 FirstViewControllers. You then ask #2 to refresh. You don't show what else happens, but at minimum #2 is not the same as the one you started with, and it is currently not on screen. So unless you put it on screen manually, this new one never is shown.

    You have the same problem in the refresh code. So FirstViewController is sitting on the screen, presumably with a table view showing. Even if you fix the previous problem and refresh the correct view controller, your refresh code creates a brand new table view. This is not the same table view, so you now have 2 table views, each within FirstViewController. You ask the second one to reload, which it does. And then you do not put this new table view onto the screen, so it is never shown. The original table view is still sitting there, and never did anything because you never told it to.

    So, stop creating new objects when you actually should be using existing objects. Then your code will work.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • merou1990merou1990 francePosts: 14New Users *
    Thank you so much for reply,
    What you should know that the secondviewcontrooler is modalview , using this viewconroller I try to acces to the tableview in firstview , so how can I access to the first one if I didn't instanciate an object. This is the first thing.Moreover in the secondview specially in " refresh method" I instanciate the tableview self.tableview= [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];tableview.dataSource = self; tableview.delegate = self; and even if I add [self.view addsubview : tableview] it still did't work.
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,676Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    When you are done with SecondViewController, simply dismiss the modal. It doesn't need to tell the FirstViewController anything. The FirstViewController can reload itself whenever it is shown in viewWillAppear. Do NOT alloc when you mean to talk to something you already have.

    And use code tags in your posts.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • merou1990merou1990 francePosts: 14New Users *
    In secondview I should call refresh method of the firstviewcontroller.What Should I add in viewwillappear of the firstview and viewwilldesapearof the second
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,676Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    You do not need to refresh from the second view. You can't even see the first view at the time, right? So what difference does it make whether or not it gets refreshed right then and there? As long as it is refreshed when you next see it, everything will be fine.

    You have the information that you need to solve the problem. So, think about it for a while, do some research if necessary, and solve it.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • merou1990merou1990 francePosts: 14New Users *
    Last thing please, When I dismiss the secondview it s not the viewdidload of the first one which is called ? .Because when I run the application I have code in viewdidload that allows me to recover all my data from database that work fine
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,676Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    I said to use viewWillAppear for a reason.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • merou1990merou1990 francePosts: 14New Users *
    I use it but it's not called
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,676Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Then either you have done something wrong or have not adequately explained the situation.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
Sign In or Register to comment.