1

I don't want to use the uialertview for the popup, that gives the user a chance to rate the app on ios. I want to use a customized popup, but this is not showing up. Besides using the iRate classes from the internet, I also create a xib, that contains the popup, that I want to appear and I changed in .h from :NSObject to :UIViewController. I commented all the code for the uialertview and in the method promptForRating, that will be triggered, I make the uiview from the xib visible, but apparently the uiview is nil.

- (void)promptForRating
{
    rateView.hidden = NO;
}

Does anybody have a suggestion about making this popup show up?

Maria Stoica
  • 211
  • 2
  • 13
  • 1
    If it is nil.. maybe you forgot to instantiate it (or didn't do it properly)? – Marc Apr 19 '13 at 07:12
  • But if i create it in the .xib, doesn't it instantiate itself?:) And I used IBOutlet for that UIView, in order to make it visible in the implementation. – Maria Stoica Apr 19 '13 at 07:13
  • UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"myNib" owner:self options:nil] objectAtIndex:0]; – Marc Apr 19 '13 at 07:18
  • myView is not nil, but unfortunately it doesn't become visible. – Maria Stoica Apr 19 '13 at 07:30
  • In your view controllers viewDidLoad: [self.view addSubView:myView] – Marc Apr 19 '13 at 07:37
  • viewDidLoad is not triggered in iRate; if I add it in initwithnibname there appears EXC_BAD_ACCESS. If I add it in the method promptForRating, xcode crashes. :) – Maria Stoica Apr 19 '13 at 08:09

1 Answers1

2

I think I get it now.. if you want to display a view, it has to be embedded in a view controller. Or in another view that is already embedded.

What you can do is

  • Access the sharedApplication of the UIApplication
  • Get all the UIWindows of that UIApplication (in reversed order, because your myView should be on top)
  • Select the UIWindow that is the default
  • Add your myView as a subview of the UIWindow

At least this is what SVProgressHUD is doing.

Here is some sample code

if(!myView.superview){
    NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];

    for (UIWindow *window in frontToBackWindows)
        if (window.windowLevel == UIWindowLevelNormal) {
            [window addSubview:myView];
            break;
        }
}

The first line is to ensure that your view is not visible atm (maybe unnecessary in your context). To dismiss the view, remove it from its superview.

Marc
  • 6,051
  • 5
  • 26
  • 56