1

I have set up a subview "popup" in my application and I want to show a navController if the user taps a button on the subview popup. I've set up the button so far, but if I tap the button the navigationController appears under my popup!? I've searched for some solution but I didn't found any. The whole controller is actually displayed in a folder which you can find here: https://github.com/jwilling/JWFolders So the viewDidLoad belong to the folder and the rootview. I tried to make it as a subview of the popup but that doesn't work too. Does anyone know how to treat that? I've set up the popup programmaticaly and the navigationController too. Thanks in advance.

My code:

The navController setup:

    - (IBAction)dothis:(id)sender {

    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

    // Set browser options.
    browser.wantsFullScreenLayout = YES;
    browser.displayActionButton = YES;


    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];

    [self presentModalViewController:navController animated:YES];

    NSMutableArray *photos = [[NSMutableArray alloc] init];
    MWPhoto *photo;
    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"star" ofType:@"png"]];
    photo.caption = @"The star is soo beateful...";
    [photos addObject:photo];

    self.photos = photos;

}


- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

The popup code:

   -(IBAction)mehr:(id)sender {
    //the popup size and content
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 440)];
    CGRect welcomeLabelRect = contentView.bounds;
    welcomeLabelRect.origin.y = 20;
    welcomeLabelRect.size.height = 40;
    UILabel *welcomeLabel = [[UILabel alloc] initWithFrame:welcomeLabelRect];

//an simple activityindicator

 activityindi = [[UIActivityIndicatorView  alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityindi.frame = CGRectMake(120, 200, 40, 40);
    [activityindi startAnimating];
    [contentView addSubview:activityindi];

   //The Imageview
    CGRect infoimagerect = CGRectMake(5, 70, 270, 200);

    UIImageView *infoimage = [[UIImageView alloc] initWithFrame:infoimagerect];

        //and the Button

cubut = [UIButton buttonWithType:UIButtonTypeCustom];
    [cubut addTarget:self
              action:@selector(dothis:)
    forControlEvents:UIControlEventTouchUpInside];
    [cubut setTitle:nil forState:UIControlStateNormal];
    cubut.frame = CGRectMake(5, 70, 270, 200);

//retrieving data from parse.com
PFQuery *query = [PFQuery queryWithClassName:@"My-Application"];
    [query getObjectInBackgroundWithId:@"My-ID"
                                 block:^(PFObject *textdu, NSError *error) {
                                     if (!error) {

//hide the Button if there is no image
                                         cubut.hidden=YES;

                                         //the headline of popup
                                         UIFont *welcomeLabelFont = [UIFont fontWithName:@"copperplate" size:20];

                                         welcomeLabel.text = [textdu objectForKey:@"header"];
                                         welcomeLabel.font = welcomeLabelFont;
                                         welcomeLabel.textColor = [UIColor whiteColor];
                                         welcomeLabel.textAlignment = NSTextAlignmentCenter;
                                         welcomeLabel.backgroundColor = [UIColor clearColor];
                                         welcomeLabel.shadowColor = [UIColor blackColor];
                                         welcomeLabel.shadowOffset = CGSizeMake(0, 1);
                                         welcomeLabel.lineBreakMode = UILineBreakModeWordWrap;
                                         welcomeLabel.numberOfLines = 2;
                                         [contentView addSubview:welcomeLabel];

//the image from parse

 if (!error) {
                                             PFFile *imageFile = [textdu objectForKey:@"image"];
                                             [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                                                 if (!error) {
                                                     UIImage *image = [UIImage imageWithData:data];
                                                     infoimage.image = image;
                                                     infoimage.contentMode = UIViewContentModeScaleAspectFit;
                                                     //show the button when the image appears
                                                     cubut.hidden = NO;




                                                     [contentView addSubview:infoimage];
                                                    //stop the activityindicator
                                                     [activityindi stopAnimating];

                                                 }
                                             }];
                                         }
 } else {
                                        //show some text 
                                         welcomeLabel.text = @"No connection!";
                                         [welcomeLabel sizeToFit];
//hide the button
                                         cubut.hidden = YES;

                                         [contentView addSubview:infoLabel];
//stop the activityindicator
                                         [activityindi stopAnimating];
                                     }

                                 }];
//add the content to the KNGModal view



 [[KGModal sharedInstance] showWithContentView:contentView andAnimated:YES];
}

My viewDidLoad

- (void)viewDidLoad
{

but.hidden = YES;
PFQuery *query = [PFQuery queryWithClassName:@"myapp"];
    [query getObjectInBackgroundWithId:@"Rgq5vankdf"
                                 block:^(PFObject *textu, NSError *error) {
                                     if (!error) {
but.hidden = NO;
                                         but.color = [UIColor colorWithRed:0.90f green:0.90f blue:0.90f alpha:1.00f];

} else {

                                         //if failure
                                        but.hidden = YES;
                                        mol.text = @"No Connection";

                                     }

                                 }];


    [super viewDidLoad];

}

Pictures:

The button to open the folder: enter image description here

The folder itself: enter image description here

The popup: enter image description here

Thanks in advance.

MasterRazer
  • 1,377
  • 3
  • 16
  • 40
  • can u show me the code for adding this pop-up.. am unable to find from here.. if its exist highlight it.. – vishy Dec 10 '12 at 15:55
  • the popup is the KNGModal so the line of code: [[KGModal sharedInstance] showWithContentView: contentView andAnimated: YES]; – MasterRazer Dec 10 '12 at 16:08
  • or look up the whole project : https://github.com/kgn/KGModal – MasterRazer Dec 10 '12 at 16:09
  • ok.. i saw the KGModal code base.. it is a pop up just like a alertView,so when it appears the view below it will be disabled, once it is dismissed the views are interacted.. so how u r using in ur app.. do u want both interactions pop-up & view below it.. – vishy Dec 11 '12 at 07:38
  • I want that the photobrowser appears above...actually on top op the popup that if the browser had been closed the popup is still there... thank you – MasterRazer Dec 11 '12 at 13:48
  • from the so far discussion i made some changes, have a look at my answer below.. – vishy Dec 12 '12 at 09:23

2 Answers2

1

From the so far discussion and debugging the code you want to have the photo browser on the pop-up with a navigation controller.

So here is the sample code which implements this functionality, have a look at it.

I have used the same KGModal sample code and extended as per the requirement. I have used Xib to have a view with navigation bar.

To dismiss the pop-up from any where in the app you can use the below line, as it is shared instance.

[[KGModal sharedInstance] hideAnimated:YES];

Update:

The reason for showing the photo browser with in folderView is, you are trying to present the photoBrowser within the folderView, so it was presenting within the folderView of very small height & not able to see any photo.

So my suggestion is, as the user taps on pop-up to view photoBrowser you just remove pop-up and present the photoBrowser from the viewController class, as other than this class everything is handled through views.

I have made the changes as per above & works fine, to the code given by you, download the code here and have a look at it.

Let me know if it fulfills your needs.

Thanks

vishy
  • 3,241
  • 1
  • 20
  • 25
  • Yes it works but the viewcontroller is only shown in the kgmodal and the kgmodal dont fits the screen size. On the Iphone 4/4s I cant see the whole dissmiss button in the navigation bar and on Iphone 5 there a some unfilled places at the bottom and top of the whole view. – MasterRazer Dec 12 '12 at 15:23
  • isnt it posible to show the controller not in the kngmodal and set it normaly? Normaly, that it appear from button like every other controller? I think the kng modal cause this issue. That was I ment that I want a normal controller displayes above all views and that dissmiss it that after the dissmiss the popup is still there – MasterRazer Dec 12 '12 at 16:15
  • am still not getting you, once u dismiss the controller immediately u can remove the pop-up from the above code right..? – vishy Dec 12 '12 at 17:15
  • wait...I tap a button in the folderviewcontroller that makes that the kng modal appears with a image and some text. I set up a button which lays on the button with the same CGRect and if I tap this button it should a new MBhotoviewcontroller appear. It appears but in the folderviewcontroller. So I cant even see the controller. – MasterRazer Dec 12 '12 at 17:18
  • nope.. still am not getting any idea how r u implementing.. create a sample code, with similar issue and send me.. – vishy Dec 12 '12 at 17:32
  • I would be happy if you could help me with this and make the code so, that I could use it... THANK YOU SO MUCH – MasterRazer Dec 12 '12 at 18:30
  • ok.. will look into it, and let you know in the morning.. as am working in IST zone.. – vishy Dec 12 '12 at 18:40
  • @NoahRaissi ok i saw ur code, now i came to know the issue. Fine i have made some changes, see my updated answer. – vishy Dec 13 '12 at 07:16
  • Thank you so much for doing that for me. I didnt know how to even do that. Thank you very much – MasterRazer Dec 13 '12 at 15:22
  • ya it completely solved my issue...but if I load an image from parse.com is it possible to show a activityindicator in this time or does it show something like that? I know it shows a MBHud or something like this if the image is loaded from a url. However, would it show or have I to implement it myself? – MasterRazer Dec 13 '12 at 18:20
  • everything does it self.. you just need to provide photos list in `MWPhoto` format.. either url or local image.. – vishy Dec 13 '12 at 18:24
  • Well now I have another problem... If I want to put this code in another Project it doesnt work for me. I have set up the whole views and imports like you did and I still got no errors but if I tap the button on the popup nothing happens. No hide...nothing. I still leave the NSLog in my project an it seems that there is something wrong with the [self.viewController launchGalleryView]; Do you know how to solve this? In the folderViewController.h I've set up the @class as my mainviewcontroller like you did with ViewController. And I think all I've set up was correctly...where is my mistake? – MasterRazer Dec 14 '12 at 17:00
  • could it be caused of no image or simply wrong spelled image? – MasterRazer Dec 14 '12 at 17:01
  • atleast your PhotoBrowser is launched..? – vishy Dec 14 '12 at 17:14
  • I think there is no cennection to the mainview – MasterRazer Dec 14 '12 at 17:26
  • could the reason be that some data is retrieved from parse? – MasterRazer Dec 14 '12 at 20:26
  • I really need your help pls. I've done all I can do. I also created a new project but in this project there was some error with no visible@interface and I couldnt solve that because all was fine...(maybe xcode is buggy)... – MasterRazer Dec 14 '12 at 20:27
  • I solved that problem now but now it gives me this error in the output: http://stackoverflow.com/questions/13888062/whose-view-is-not-in-window-hierarchy-issue – MasterRazer Dec 15 '12 at 00:26
0

I noticed this line of code:

[[KGModal sharedInstance] showWithContentView: contentView andAnimated: YES];

And I can only think that, since it is a singleton, it adds the contentView on the UIApplication's key window. If that is the case, then a modal view controller will always be below the popup. You can solve this by adding a new method to the KGModal class

- (void) showWithContentView: (UIView*)           contentView
            inViewController: (UIViewController*) controller
                 andAnimated: (BOOL)              animated;

the method should show the popup in the specified controller's view; you should use that method instead.

Edit

After some more digging, I found that KGModal displays the popup on another window. The quickest fix would be to dismiss the popup, then show the nav controller.

Kenn Cal
  • 3,659
  • 2
  • 17
  • 18
  • how can I dissmiss the popup and show the navcontroller immediatedly? – MasterRazer Dec 08 '12 at 19:27
  • and actually this is my real problem! http://stackoverflow.com/questions/13773682/subview-displays-wrong – MasterRazer Dec 08 '12 at 20:16
  • Use [[KGModal sharedInstance] hideAnimated]; – Kenn Cal Dec 10 '12 at 02:10
  • But is there a way to display the navController so that it appears on top of the popup? Because I dont want to that the popup closes and the nacController appears. I want that the navController appears and the popup is still there. I would be happy if you could give me some sample code. – MasterRazer Dec 10 '12 at 14:36