-3

hi i am new to ios programing and i am developing a calendar app in which i am using tabbarcontroller which have 5 viewcontroller. My probelm is that in 2nd viewcontroller i want to change the date wich is displaying in the first viewcontroller, how can i do this. pls help....

i had made a property in appdelegate class

@property(nonatomic,assign)NSString *date;

AND THEN made a object of appdelegate in both the view controller and then in 2nd view controller

AppDelegate *obj=[[AppDelegate alloc]init];
    obj.date=@"ABCDSE";

and in 1st view controller

 AppDelegate *obj=[[AppDelegate alloc]init];
    mylabel.text=obj.date;
Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59

2 Answers2

0

You don't create an app delegate, you get a reference to it:

AppDelegate *ad = [[UIApplication sharedApplication]delegate];

Then you access the string:

mylabel.text = ad.date;
TigerCoding
  • 8,710
  • 10
  • 47
  • 72
0

Try this

FirstViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSString *strTemp = @"Pass string here";
  FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

  firstView.Str = strTemp;

  [self.navigationController pushViewController:firstView  animated:YES];
}

SecondViewController.h

@interface SecondViewController: UIViewController
@property(nonatomic,retain) NSString *Str;
@end

And check out some video tuts

http://www.verious.com/tutorial/ios-5-passing-data-between-view-controllers/ http://www.verious.com/tutorial/iphone-development-tutorial-passing-data-to-another-view/

Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59