Data transfer between tabs in iOS

This is my first application that I am trying to do on my own, and I have some questions. I want to have 4 tabs, and in the first title "HomeView" I am parsing JSON data (this has been done so far).

But what I want is some of the data that is being analyzed to be visible on other tabs (and there is no need to analyze it again).

So, parts of my HomeView code are here:

#import "HomeView.h"

@interface HomeView ()
@end

@implementation HomeView


//other code

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//data fetched
parsed_date=[res objectForKey:@"date"];
 NSLog(@"Date:%@",parsed_date);
[UIAppDelegate.myArray  addObject:parsed_date];
        }

and I see that "parsed_date" prints correctly.

So, I want this parsed_date to be visible in OtherView.

This is my code, but I cannot print it.

OtherView.m

#import "OtherView.h"
#import "HomeView.h"
#import "AppDelegate.h"

@interface OtherView ()

@end

@implementation OtherView
@synthesize tracks_date;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //preview value of other class
   tracks_date = [UIAppDelegate.myArray objectAtIndex:0];
NSLog(@"Dated previed in OtherView: %@", tracks_date);
}

and (null).

delegate.h application code added

#import <UIKit/UIKit.h>

#define UIAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) NSArray *myArray;

@end

So can you offer me a solution?

+5
source share
4

.

- :

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

delegate.myProperty = @"My Value";

:

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *valueInTab = delegate.myProperty; 
+11

HomeView , - . connectionDidFinishLoading, .

- , , , AppDelegate, "singleton".

+2

, .

. . .

AppDelegate.h

#define UIAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

@property (nonatomic, strong) NSArray *myArray;

TabView1.m

#import "AppDelegate.h"

SomeObject *myObject = [UIAppDelegate.myArray objectAtIndex:0];

, , , . , .

+1

, HomeView. . , nib.

, - IBOutlet, "" InterfaceBuilder.

@interface OtherView ()
    IBOutlet HomeView *homeView;
@end

@implementation OtherView
@synthesize tracks_date;

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"Dated previed in OtherView: %@", homeView.parsed_date);
}

- (void)dealloc:
{
    [homeView release];
}

,

InterfaceBuilder ( IBOutlets IBAction,...) .

I think this video is a good demonstration of how this concept works.

+1
source

All Articles