-2

I've got a TableViewController where I want to display some data from AppDelegate.m

To do this I put some code in AppDelegate to Assign my Array to the property of the viewController, but I've got some problem with the syntax to do this.

My storyboard map is like that :

  • The storyboard’s initial view controller is a Tab Bar Controller
  • The CalculateViewController sits inside a navigation controller in the first tab
  • The AircraftSelectViewController sits inside the first cell of my CalculateViewController

So I've got this part of code :

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarControllerNew viewControllers][0];

But I don't know how to explain to AppDelegate that my AircraftSelectViewController (UITableViewController) sits inside another UITableViewController (CalculateViewController).

Anyone knows how to do this ? thx

EDIT :

I would like to do something like this, but i don't find the right syntax :

UITabBarController *tabBarControllerNew = (UITabBarController *)self.window.rootViewController;
    UINavigationController *navigationControllerNew = [tabBarControllerNew viewControllers][0];
    CalculateViewController *calculateViewController = [navigationControllerNew viewControllers][0];
    AircraftSelectViewController *aircraftSelectViewController = [calculateViewController tableView][0];
    aircraftSelectViewController.aircraft = _aircraft;
testoverblaireau
  • 179
  • 5
  • 19
  • You can pass your array to CalculatorViewController then you can assign that array to AircraftSelectViewController in cellForRowAtIndexPath. If you use custom tableview cell should have the reference to that array. – jailani Dec 30 '13 at 11:37
  • can you show the code how you are assigning array to AircraftSelectViewController? – Suhit Patil Dec 30 '13 at 11:39
  • Get the values of arrays in the CalculateViewController and then forward that values to AircraftSelectViewController and use the array there in AircraftSelectViewController. – iShwar Dec 30 '13 at 11:50
  • @semlh : simply learn how to transfer the data from one viewcontroller to another in iOS , Google Can help you very well for this. Best Luck. – iShwar Dec 30 '13 at 11:57
  • Refer This Stack-overflow Question's answers your problem will be solved. [1]: http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers/20048208#20048208 – iShwar Dec 30 '13 at 12:07
  • I add this to my CalculateViewController.m : - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"pickAircraft"]) { AircraftSelectViewController *aircraftSelectViewController = segue.destinationViewController; aircraftSelectViewController.aircraft = _aircraft; } } And it works fine. Thx for helping. – testoverblaireau Dec 30 '13 at 12:56

2 Answers2

0

I think you can define a variable in AppDelegate

@property(nonatomic, strong)    NSMutableArray *galleryImages;

and In your viewController, you can get and set the value Of this arrays like

#import "Appdelegate.h"

init your appDelegate object and

appDelegate.galleryImages = // assign here;
Mani
  • 17,549
  • 13
  • 79
  • 100
Retro
  • 3,985
  • 2
  • 17
  • 41
  • In this case i've got my Data in Appdelegate.m and i just want to tell it that my AircraftSelectViewController is in CalculateViewController, in order to assign the array like that : aircraftSelectViewController.aircraft = _aircraft; – testoverblaireau Dec 30 '13 at 11:43
  • I am not sure what do you want ? – Retro Dec 30 '13 at 12:30
  • I wanted to transfer data from one view controller to another. I did it with : (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"pickAircraft"]) { AircraftSelectViewController *aircraftSelectViewController = segue.destinationViewController; aircraftSelectViewController.aircraft = _aircraft; Thx for helping ! – testoverblaireau Dec 30 '13 at 13:06
  • it should work so did you check the value of array before assigning that its not null – Retro Dec 30 '13 at 13:08
  • Indeed, it works. I was not very clear in my comment ;) – testoverblaireau Dec 30 '13 at 13:11
0

in CalculateViewController.h

create a array property with the name aircraft.

@property(nonatomic, strong) NSArray *aircraft;

in AppDelegate.m

 CalculateViewController *calculateViewController = [navigationControllerNew viewControllers][0];
    calculateViewController.aircraft = _aircraft //or array which you have created in app delegate.

in CalculateViewController.m

in cellForRowAtIndexPath: method

assign the cell your array value.

cell.textLabel.text = [self.aircraft objectAtIndex:indexPath.row];
Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
  • Thx for your answer. I've already do it and it works fine. But i would like to assign my Array in the AircraftSelectViewController. I will try to transfer data between the two ViewController. – testoverblaireau Dec 30 '13 at 12:21