1

my iOS application use storyboard

it have 2 view controllers: - main storyboard view controller - and popover view controller with some objects in it

i've got a button on main view controller and it creates programing every time i run the application:

*CGRect buttonFrame = CGRectMake(10., 10., 120., 50.);

oneButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[oneButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"someImage.png", img]] forState:UIControlStateNormal];
[oneButton setTag:img];
[oneButton setFrame:buttonFrame];
[oneButton addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:oneButton];*

the action of this button show my popover view like that:

*- (void) pressButton:(id)sender {

popoverViewController *popoverFrame = [self.storyboard instantiateViewControllerWithIdentifier:@"myPopoverView"];

popoverWithObjects = [[UIPopoverController alloc] initWithContentViewController:popoverFrame];

[popoverWithObjects presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

}*

from now the situation is, that i can't send to my button any message or result. i want to say to my program button (note - i've got only sender of this button action:@selector(pressButton:) ) that popover return some result or some action of an object in popover send anything (string for example) Or in another words when i interact with any object like button on popover view, i want to change parent buttons title label

Peter Sukhov
  • 11
  • 1
  • 2

3 Answers3

0

How about writing a function on your Main View Controller to do what you want. Then call that function from the popover? (i.e. use 'prepare for segue' to send the popover the id of the Main View Controller, and then use that id to call the function on Main View from the popover)

MorganIsBatman
  • 1,000
  • 8
  • 13
0

You need to use delegate. Check out my answer to this similar question from this SO.

Edit: Link to tutorial on Storyboard and delegate pattern usage. And my original answer to delegate on this SO

Community
  • 1
  • 1
user523234
  • 14,323
  • 10
  • 62
  • 102
  • U know, i tried it. i can't make delegation in storyboard app... Anyway thanks for u'r answer. And for the link, it really helpfull – Peter Sukhov Feb 19 '12 at 22:42
  • how to make delegation for parent object (button in my case) – Peter Sukhov Feb 19 '12 at 22:47
  • I think you are confused between appDelegate and other classes' delegate pattern. While appDelegate is not available under Storyboard, using delegate pattern to callbacks are still valid technique. – user523234 Feb 20 '12 at 02:58
  • Looking at your code, I am guessing "popoverViewController" or "myPopoverView" is your child view controller.  And your main view controller (where you have the button) is your parent view controller.  Having these two pieces of information, you should be able to follow the pattern from the other mentioned SO answer.  I just also edited my answer above to include another tutorial link on Storyboard that illustrated how to use delegate pattern. – user523234 Feb 20 '12 at 03:11
  • @peter, see my answer here for a detailed explanation of setting up a delegate and delegate protocol - http://stackoverflow.com/questions/9043801/cant-connect-iboutlet-using-xcode-4-2-1-ios-5-0-and-storyboards/9046428#9046428. – T.J. Feb 20 '12 at 07:18
  • your link to tutorial is really interesting, but unfortunately i have no segue to my popover view!!! that's all because from the beginning i have no button on main storyboard view, i create it later in code... and so, i can't bind segue and give it a name, as in your tutorial – Peter Sukhov Feb 20 '12 at 07:27
  • Perhaps someone else can address this question. – user523234 Feb 20 '12 at 15:09