I'm just a beginner in iOS Devp and stuck with this problem since last 2days. What I am trying to do is I've two view controllers, the first View Controller consists of 2 buttons and I want to load a specific type of data in next View controller on respective button action.
What I did is as follows : I've two ViewControllers connected using segue with id "showDetailSegue", 1. ViewController 2. SecondVC I want to update label on SecondVC when the button on ViewController is tapped.
//ViewController.h
#import <UIKit/UIKit.h>
#import "SecondVC.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
//ViewController.m
#import "ViewController.h"
#import "SecondVC.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
NSString *str = @"my string data..";
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showDetailSegue"]){
SecondVC *controller = segue.destinationViewController;
controller.getString = str;
controller.testLabel.text = str;
}
}
@end
//SecondVC.h
#import <UIKit/UIKit.h>
@interface SecondVC : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *testLabel;
@property (nonatomic, strong) NSString *getString;
@end
//SecondVC.m
Please help me with a straightforward and clear explanation.
Thanks in advance.!