How to retrieve passed data from another view controller? - Objective-C
up vote
-2
down vote
favorite
SendDataVc.m - Sending data from.
GetDataVC.m - Retrieving the data sent from SendDataVc.m
SendDataVC.m:
NSString *theData = @"Sending data";
GetDataVC *passdataVC = [[GetDataVC alloc] init];
passdataVC.theData = theData;
GetDataVC.h:
@property (strong, nonatomic) NSString *theData;
GetDataVC.m:
-(void) getData
{
NSLog( @"%@", _theData);
}
I tried doing this way but I got null instead.
objective-c xcode
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-2
down vote
favorite
SendDataVc.m - Sending data from.
GetDataVC.m - Retrieving the data sent from SendDataVc.m
SendDataVC.m:
NSString *theData = @"Sending data";
GetDataVC *passdataVC = [[GetDataVC alloc] init];
passdataVC.theData = theData;
GetDataVC.h:
@property (strong, nonatomic) NSString *theData;
GetDataVC.m:
-(void) getData
{
NSLog( @"%@", _theData);
}
I tried doing this way but I got null instead.
objective-c xcode
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
That seems correct. Now the questions is where is calledgetData? Do you use Storyboard & Segue? How is presentedpassdataVC? Do you do a present? a Push?
– Larme
Nov 7 at 9:10
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
SendDataVc.m - Sending data from.
GetDataVC.m - Retrieving the data sent from SendDataVc.m
SendDataVC.m:
NSString *theData = @"Sending data";
GetDataVC *passdataVC = [[GetDataVC alloc] init];
passdataVC.theData = theData;
GetDataVC.h:
@property (strong, nonatomic) NSString *theData;
GetDataVC.m:
-(void) getData
{
NSLog( @"%@", _theData);
}
I tried doing this way but I got null instead.
objective-c xcode
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SendDataVc.m - Sending data from.
GetDataVC.m - Retrieving the data sent from SendDataVc.m
SendDataVC.m:
NSString *theData = @"Sending data";
GetDataVC *passdataVC = [[GetDataVC alloc] init];
passdataVC.theData = theData;
GetDataVC.h:
@property (strong, nonatomic) NSString *theData;
GetDataVC.m:
-(void) getData
{
NSLog( @"%@", _theData);
}
I tried doing this way but I got null instead.
objective-c xcode
objective-c xcode
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 7 at 9:33
Cœur
16.8k9101139
16.8k9101139
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 7 at 7:56
sha he ra
1
1
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
That seems correct. Now the questions is where is calledgetData? Do you use Storyboard & Segue? How is presentedpassdataVC? Do you do a present? a Push?
– Larme
Nov 7 at 9:10
add a comment |
That seems correct. Now the questions is where is calledgetData? Do you use Storyboard & Segue? How is presentedpassdataVC? Do you do a present? a Push?
– Larme
Nov 7 at 9:10
That seems correct. Now the questions is where is called
getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?– Larme
Nov 7 at 9:10
That seems correct. Now the questions is where is called
getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?– Larme
Nov 7 at 9:10
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:
- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}
add a comment |
up vote
-1
down vote
You can't instantiate a UIViewController that way.
Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:
GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
passdataVC.theData = theData;
Yes you can. You are assuming that theGetDataVCis in a Storyboard. But you can do all by code.
– Larme
Nov 7 at 9:10
As stated in Apple document,initisn't a designated initializer forUIViewController. Actually, you can useinitWithNibName:bundle:but notinit.
– RyanB
Nov 7 at 9:30
I don't see an issue with that.initWithNibName:bundle:is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
add a comment |
up vote
-1
down vote
Where you execute the function getData?
If you execute getData at viewDidLoad or init or somewhere before you set the data.
You can execute the function through a button.
I think that will deal the problem.
add a comment |
up vote
-1
down vote
Just implement the setter of theData property.
Paste the code below to your GetDataVC.m.
- (void)setTheData:(NSString *)theData {
_theData = theData;
NSLog(@"theData has set: %@", _theData);
}
refrence: Apple Document
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:
- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}
add a comment |
up vote
0
down vote
I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:
- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}
add a comment |
up vote
0
down vote
up vote
0
down vote
I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:
- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}
I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:
- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}
edited Nov 9 at 6:09
answered Nov 8 at 10:27
RateRebriduo
65
65
add a comment |
add a comment |
up vote
-1
down vote
You can't instantiate a UIViewController that way.
Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:
GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
passdataVC.theData = theData;
Yes you can. You are assuming that theGetDataVCis in a Storyboard. But you can do all by code.
– Larme
Nov 7 at 9:10
As stated in Apple document,initisn't a designated initializer forUIViewController. Actually, you can useinitWithNibName:bundle:but notinit.
– RyanB
Nov 7 at 9:30
I don't see an issue with that.initWithNibName:bundle:is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
add a comment |
up vote
-1
down vote
You can't instantiate a UIViewController that way.
Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:
GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
passdataVC.theData = theData;
Yes you can. You are assuming that theGetDataVCis in a Storyboard. But you can do all by code.
– Larme
Nov 7 at 9:10
As stated in Apple document,initisn't a designated initializer forUIViewController. Actually, you can useinitWithNibName:bundle:but notinit.
– RyanB
Nov 7 at 9:30
I don't see an issue with that.initWithNibName:bundle:is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
add a comment |
up vote
-1
down vote
up vote
-1
down vote
You can't instantiate a UIViewController that way.
Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:
GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
passdataVC.theData = theData;
You can't instantiate a UIViewController that way.
Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:
GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
passdataVC.theData = theData;
answered Nov 7 at 8:06
RyanB
8481521
8481521
Yes you can. You are assuming that theGetDataVCis in a Storyboard. But you can do all by code.
– Larme
Nov 7 at 9:10
As stated in Apple document,initisn't a designated initializer forUIViewController. Actually, you can useinitWithNibName:bundle:but notinit.
– RyanB
Nov 7 at 9:30
I don't see an issue with that.initWithNibName:bundle:is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
add a comment |
Yes you can. You are assuming that theGetDataVCis in a Storyboard. But you can do all by code.
– Larme
Nov 7 at 9:10
As stated in Apple document,initisn't a designated initializer forUIViewController. Actually, you can useinitWithNibName:bundle:but notinit.
– RyanB
Nov 7 at 9:30
I don't see an issue with that.initWithNibName:bundle:is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
Yes you can. You are assuming that the
GetDataVC is in a Storyboard. But you can do all by code.– Larme
Nov 7 at 9:10
Yes you can. You are assuming that the
GetDataVC is in a Storyboard. But you can do all by code.– Larme
Nov 7 at 9:10
As stated in Apple document,
init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.– RyanB
Nov 7 at 9:30
As stated in Apple document,
init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.– RyanB
Nov 7 at 9:30
I don't see an issue with that.
initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.– Larme
Nov 7 at 9:34
I don't see an issue with that.
initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.– Larme
Nov 7 at 9:34
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
Ok, you're right. Now, we have to wait for more detail from OP.
– RyanB
Nov 7 at 9:50
add a comment |
up vote
-1
down vote
Where you execute the function getData?
If you execute getData at viewDidLoad or init or somewhere before you set the data.
You can execute the function through a button.
I think that will deal the problem.
add a comment |
up vote
-1
down vote
Where you execute the function getData?
If you execute getData at viewDidLoad or init or somewhere before you set the data.
You can execute the function through a button.
I think that will deal the problem.
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Where you execute the function getData?
If you execute getData at viewDidLoad or init or somewhere before you set the data.
You can execute the function through a button.
I think that will deal the problem.
Where you execute the function getData?
If you execute getData at viewDidLoad or init or somewhere before you set the data.
You can execute the function through a button.
I think that will deal the problem.
answered Nov 7 at 8:18
Chenjtc
102
102
add a comment |
add a comment |
up vote
-1
down vote
Just implement the setter of theData property.
Paste the code below to your GetDataVC.m.
- (void)setTheData:(NSString *)theData {
_theData = theData;
NSLog(@"theData has set: %@", _theData);
}
refrence: Apple Document
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-1
down vote
Just implement the setter of theData property.
Paste the code below to your GetDataVC.m.
- (void)setTheData:(NSString *)theData {
_theData = theData;
NSLog(@"theData has set: %@", _theData);
}
refrence: Apple Document
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Just implement the setter of theData property.
Paste the code below to your GetDataVC.m.
- (void)setTheData:(NSString *)theData {
_theData = theData;
NSLog(@"theData has set: %@", _theData);
}
refrence: Apple Document
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Just implement the setter of theData property.
Paste the code below to your GetDataVC.m.
- (void)setTheData:(NSString *)theData {
_theData = theData;
NSLog(@"theData has set: %@", _theData);
}
refrence: Apple Document
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Nov 7 at 8:20
SerKo
1173
1173
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
sha he ra is a new contributor. Be nice, and check out our Code of Conduct.
sha he ra is a new contributor. Be nice, and check out our Code of Conduct.
sha he ra is a new contributor. Be nice, and check out our Code of Conduct.
sha he ra is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185424%2fhow-to-retrieve-passed-data-from-another-view-controller-objective-c%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
That seems correct. Now the questions is where is called
getData? Do you use Storyboard & Segue? How is presentedpassdataVC? Do you do a present? a Push?– Larme
Nov 7 at 9:10