0

I am struggling to make a simple thing (at least I think it's simple) but I just can't do it!

I will try to explain a little bit.

It's an app which displays information. When the user is inside a view, he can click on a button, which displays a popoverview, where he can choose which information he wants to know.

Actually, I can't create an action that changes the UILabel text I created in the main view when the user clicks on the popoverview's buttons.

Anyone has any idea?

Just for you to know: the main view I created a class for it, and also for the popoverview. Although, the popover view I created its design in a XIB file (I don't know if this is important, that's why I am putting this).

Well, I hope you guys were able to understand my question.

Thanks in advance.

Fernando.

  • 2
    I see that you are a beginner (don't have any problem with that) but in my opinion SO is not the place where you post a question straight forward without any previous research, I googled your question and there are plenty of SO post that can show you how to do what you need. I think you should have a look over them, try some of them and if something won't work as you expected, then post a question on SO. – danypata Jul 02 '13 at 18:42
  • Yeah, just like you said, I am a beginner. I did what you said, I tried a lot and I said to myself: SO is gonna be my last shot, that's why I posted my question here. But thanks anyway :) – Fernando Augusto Marins Jul 04 '13 at 13:54
  • I wrote my first comment as a suggestion, it doesn't bother me that you posted a question on SO, if I don't like the question I won't answer it, but other SO user won't like it and you will end up with closed questions or downvotes ;) – danypata Jul 04 '13 at 14:03

2 Answers2

0

Just create a property from the viewcontroller and access it from the consumer (other viewcontroller )

RollRoll
  • 8,133
  • 20
  • 76
  • 135
0

You will have to use delegation in order to see changes in the main view when you are making different actions inside the popover. First, you need to create a protocol inside your popover controller header file:

#import <Foundation/Foundation.h>

@class MyPopoverController;
@protocol MyPopoverDelegate
- (void)valueChanged:(NSString*) newVal;
@end

@interface MyPopoverController: UIPopoverController 

@property (weak) id<MyPopoverDelegate> delegate;

@end

Then in .m you implement it like this:

 - (void) someActionOccured
    {
        if([self.delegate respondsToSelector:@selector(valueChanged:)]){
           [self.delegate valueChanged:valueYouWantToSendBack];
        }
    }

Remember that in your main class you have to implement MyPopoverDelegate protocol:

@interface MainViewController: UIViewController <MyPopoverDelegate>

And when you instantiate your popover controller:

/*
** inside MainViewController.m
*/ 
// remember to assign it's delegate 
MyPopoverController *popoverController = [MyPopoverController alloc] init]; 
popoverController.delegate = self;

Also, you'll have to implement the protocol's method:

/*
** inside MainViewController.m
*/ 
- (void)valueChanged:(NSString*) newVal
{
// process the string and display it where you need it
}
Teo
  • 3,394
  • 11
  • 43
  • 73