Second view controller modal file.
#import "View2Controller.h"
@interface View2Controller ()
@property (weak, nonatomic) IBOutlet UILabel *textLabel;
@end
@implementation View2Controller
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
for (id object in self.array) {
// do something with object
NSLog(@"%@", object);
}
self.textLabel.text = self.array.lastObject;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
Declare your array in header.
#import <UIKit/UIKit.h>
@interface View2Controller : UIViewController
@property NSArray *array;
@end
And here is main view controller.
#import "ViewController.h"
#import "View2Controller.h"
@interface ViewController ()
@property NSArray *array;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.array = [NSArray arrayWithObjects:@"test",@"string2", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnListClicked:(UIButton *)sender {
[self performSegueWithIdentifier:@"passData" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"passData"]) {
View2Controller *vc = [segue destinationViewController];
vc.array = self.array;
}
}
@end
My Storyboard -
