2

I create custom login page by using UIAlerView subclass. Now when i click on button it opens up UIAlertView I want to change the main view based on which button is pressed.

But as all implementation of UIAlerView is in another class though i change the view it doesn't retain that as that class variable doesn't get it's value.

Can anyone please help me with this? I can post the code if required.

Thank you, Ankita

Mac
  • 14,385
  • 9
  • 62
  • 78
Anks
  • 235
  • 4
  • 15

2 Answers2

1

You can use a custom init method like below for alertView and store the _sender in global or class variable. like

id sender;
- (id)initWithSender:(id)_sender
{
    self = [super init];
    if (self) {
        sender=_sender;
    }
    return self;
}

from RootVC/bgview initialize alertView as follows and define a method named

-(void) alertIndexSelected:(NSInterger) index;

{

//change the backgound view based on button selected }

in rootvc/your main view.
  alertViewobj =[[alertView alloc] initWithSender:self];

when the button is selected on alertview call the below method, this will notify your rootvc about which index of alert is pressed. use following alertview delegate.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[sender alertIndexSelected: buttonIndex];
}




pradeepa
  • 4,054
  • 5
  • 30
  • 41
1

If you are planning to use delegate methods then I think you need to referrer to some of these links.

How to use custom delegates in Objective-C

How do I create delegates in Objective-C?

http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html

I hope this will help you a great deal in understanding delegates.

Cœur
  • 34,719
  • 24
  • 185
  • 251
Robin
  • 9,999
  • 5
  • 48
  • 75