Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-31-2012, 01:32 AM   #1 (permalink)
k2c
Registered Member
 
Join Date: Oct 2009
Posts: 26
k2c is on a distinguished road
Unhappy Passing Data between Tab bar views

Hi all!

I have been trying to figure out how to pass data between tab bar views, but no success. Put name in the Textfield and push a button on firstview, however a label on secoundview doesn't update.
I found example codes for OS 4.3, but it doesn't work on OS 5 with storyboard... Here is a storyboard screenshot and codes. What's wrong with them? Please help!



FirstViewController.h
Code:
#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface FirstViewController : UIViewController <UITextFieldDelegate> {
    
    NSString *fullName;
    
    
}
@property (nonatomic, retain) NSString *fullName;
@property (retain, nonatomic) IBOutlet UITextField *nameTextField;

- (IBAction)nextVCButton:(id)sender;


@end

FirstViewController.m
Code:
#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation FirstViewController
@synthesize nameTextField, fullName;


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}


- (IBAction)nextVCButton:(id)sender {
    
    SecondViewController *secView = [[SecondViewController alloc] initWithNibName:@"SecondViewController"
                                                                            bundle:nil];
    [secView setFullName:fullName];
    
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   
    SecondViewController *ivc = [segue destinationViewController];
    ivc.fullName = fullName;
}

-(BOOL) textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
    
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    self.fullName = [textField text];
    return YES;
    
}
@end

SecondViewConroller.h
Code:
#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController{
    
    NSString *fullName;
    UILabel *nameLabel;
    
}
@property (retain, nonatomic) NSString *fullName;
@property (retain, nonatomic) IBOutlet UILabel *nameLabel;

@end
SecondViewController.m
Code:
#import "SecondViewController.h"

@implementation SecondViewController
@synthesize nameLabel, fullName;
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    nameLabel.text = fullName;
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    
    
    [super viewWillAppear:animated];
  //  [self.nameLabel setText:fullName];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
k2c is offline   Reply With Quote
Old 02-06-2012, 11:09 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 6
dessicant is on a distinguished road
Default

try using the MVC pattern. you have the views and the controllers, but no model. store the data in a separate model class, and then you can update or read it from both controllers while keeping them loosely coupled.
dessicant is offline   Reply With Quote
Old 02-09-2012, 12:18 AM   #3 (permalink)
k2c
Registered Member
 
Join Date: Oct 2009
Posts: 26
k2c is on a distinguished road
Default

Thank you, dessicant! I'll try that.
k2c is offline   Reply With Quote
Reply

Bookmarks

Tags
bar, data, passing, storyboard, tab

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 422
17 members and 405 guests
Atatator, chiataytuday, condor304, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, mraalex, n00b, PowerGoofy, QuantumDoja, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0