Passing parameter from one xib to another xib


I have label in my secondviewcontroller. I would like to pass button index from firstviewcontroller to secondviewcontroller label. When I press button, it goes to second viewcontroller but label is nil

<strong>// FirstViewController.m</strong>

NSInteger index = [carousel indexOfItemViewOrSubview:sender]; int ind=index; SecondViewController *sVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]]; sVC.myLabel.text=[NSString stringWithFormat:@"%d",ind]; [self presentModalViewController:sVC animated:YES];


@property (strong, nonatomic) IBOutlet UILabel *myLabel;


@synthesize myLabel; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSLog(@"%@",myLabel.text); }


In the SecondViewController.h add another property:

@property (nonatomic) NSInteger index;

Then in the FirstViewController.m pass the value of index to the index of the second view:

NSInteger index = [carousel indexOfItemViewOrSubview:sender]; int ind=index; //now you don't need this SecondViewController *sVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]]; sVC.myLabel.text=[NSString stringWithFormat:@"%d",ind]; // New line sVC.index = index; [self presentModalViewController:sVC animated:YES];


  • iOS: Crash at setSelectedViewController in tabBarController
  • Inserting alert view but not functioning
  • Pushing View Controllers in UITableViewController Grouped
  • How do I push many Views from one View using UINavigationController
  • How can I play a movie locally with the MPMoviePlayerViewController?
  • loop input files inside a function in R
  • find out the largest element from the given row to the end
  • How to pass variable from UIViewController to delegate UITableViewController
  • Matlab - Finding values within a matrix
  • Memory leaks when playing a video iPhone
  • Playing HLS (m3u8) in Cocoa OS X AVPlayer - Swift
  • UIWebview manipulating SVG 'on the fly'
  • Configuration profile installation on iPhone Programatically
  • Why does audio work in the simulator but not on my iPad?
  • How can I programatically get the list of frameworks and libraries included in an ios project?
  • Return only columns containing NA in R
  • var query not returning required results
  • NSBundle finds mp3 file but not m4a when trying to instantiate AVAudioPlayer
  • How to set an indexed value in a matrix based on another matrix's values
  • WCF multiple services same contract in same Config
  • NSURL Always Returns Nil
  • How to save my result as indexed array?
  • How to add a custom HTTP header to ajax request with js or jQuery
  • SWIFT uiviewcontroller init
  • AVAudioPlayer doesn't load sound
  • How to implement AVAudioPlayer Inside Singleton Method?
  • Confused about how to update my datasources on my UITableView after app has been released
  • Unable to add the file iOS application bundle
  • Display a .pdf in an iOS app without downloading it from the internet
  • How to access recipient on sent messages page with mailboxer
  • Click on button in another program - FindWindow, C#
  • c# open webrowser in many tab
  • How to Cache Real-time Data?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • AT Commands to Send SMS not working in Windows 8.1
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Sorting a 2D array using the second column C++
  • java string with new operator and a literal