My issue for my function is I am not sure how to pass the data which i selected, and back to the previous view controller. The link is to the whole paragraph,http://pastebin.com/AtMjLD66 (sorry I don't have 10 reputations, sorry about the inconvenience ) Cheer.
4 Answers
You would use the delegate pattern to send a message back to the view controller's delegate (which you could set to the presenting view controller), passing along whatever information you need to about the selection.
-
OK, so first I add http://pastebin.com/TdAcUxxh this to the advancedVC.h Second this is my advancedDetailVC.h looks like this http://pastebin.com/rB2rgL3H . Third, I am not sure about your point 4(the link you gave me), where should I add those code?? Four, I add these into my advancedDetailVC.m http://pastebin.com/EWFeSrSY . But what should i change for the someDataArray?? and the (void)advancedSelected:(NSArray *)selectedAdvanced. – hsiehboi Oct 16 '13 at 10:56
-
Last, the function should be able to pass all the data back. ex. "Chef 1" will pass back to "Chef Name"; "< 10 mins" should pass back to "Prep Time"; "Dietary 1" should be pass back to "Dietary Needs". Can you give me some help please @@ – hsiehboi Oct 16 '13 at 10:57
I would recommend delegates for this but if you don't want to do so, NSNotification would save your day here.
Add this is in advanceVC.m probably in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someThingSelectedInDetail:) name:@"someThingSelectedInDetail" object:nil];
- (void)someThingSelectedInDetail:(NSNotification*)notificationObject
{
NSString *chefName = notificationObject.object;
NSLog(@"Chef Name from notification: %@",chefName);
}
And in didSelect of advanceDetailVC.m do this.
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: cell.textLabel.text];
Instead of passing a label's text you have the indexpath here so take it directly from the array and pass it in the notification like this
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: [detailArray objectAtIndex:indexPath.row]];

- 10,998
- 6
- 50
- 93
-
But if i want every data can push back , should i add any code else?? ex. in the "Dietary Needs", if you click "Dietary 1", it will push the "Dietary 1" back. then in the "Chef Name", you click "Chef 3", it can push back as well etc.... – hsiehboi Oct 16 '13 at 07:09
-
You can pass anything in the notification (in the example I am passing NSString) but the only thing you have to do is the receiver side handling, it should not get anything other than a string when it expects a string. – Satheesh Oct 16 '13 at 10:50
-
Sorry, I am still very confuse, and where should I add this line [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someThingSelectedInDetail:) name:@"someThingSelectedInDetail" object:nil]; – hsiehboi Oct 17 '13 at 14:01
-
You have to add it in the view controller that presents the modal view. It is the observer for the notification, so when it is fired you are getting data about which row was selected and you are doing something with it. Please see my edit, I have added even the functions where you have to place em. – Satheesh Oct 17 '13 at 14:41
Assuming you want it for iOS, a simple call :
[[[UIApplication sharedApplication] delegate] doSomething];
or Since you only have one view controller, the generic way (independent of how your app was set up):
UIViewController *vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];

- 8,570
- 6
- 46
- 65
You can use nsuserdefault to save data and then you can retrieve back in the previous class

- 90
- 1
- 7
-
1NSUserDefaults is for storing user preferences, it's not meant to be a globally accessible area for transient data storage. – Andrew Oct 16 '13 at 04:52