2012-12-08 154 views
1

我已经在我的应用程序中设置了子视图“弹出”,我想显示一个navController,如果用户点击子视图弹出按钮。到目前为止,我已经设置了按钮,但是如果我点击按钮导航控制器出现在我的弹出窗口下!我寻找了一些解决方案,但我没有找到任何解决方案。整个控制器实际显示在一个文件夹中,您可以在这里找到:https://github.com/jwilling/JWFolders因此,viewDidLoad属于文件夹和rootview。 我试图将它作为弹出窗口的子视图,但这不起作用。有谁知道如何治疗?我已经设置了弹出式的programmaticaly和navigationController。 在此先感谢。显示导航控制器顶部

我的代码:

的navController设置:

- (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; 
} 

弹出代码:

-(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]; 
} 

我的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]; 

} 

图片:

打开文件夹按钮: enter image description here

文件夹本身: enter image description here

弹出: enter image description here

在此先感谢。

+0

u能告诉我的代码添加这个弹出..我无法从这里找到..如果它存在突出它.. – vishy

+0

弹出是KNGModal的代码,以便行: [KGModal sharedInstance] showWithContentView:contentView andAnimated:YES]; – MasterRazer

+0

或查看整个项目:https://github.com/kgn/KGModal – MasterRazer

回答

1

从目前为止的讨论和调试代码中,您想要使用导航控制器弹出照片浏览器。

所以这里是sample code它实现了这个功能,看看它。

我已经使用了相同的KGModal示例代码并根据需要进行了扩展。我已经使用Xib具有导航栏的视图。

要关闭应用程序中的任何位置的弹出窗口,您可以使用下面的行,因为它是共享实例。

[[KGModal sharedInstance] hideAnimated:YES]; 

更新:

原因出在文件夹视图是,你正试图将文件夹视图中呈现photoBrowser,所以这是非常小的高度&的文件夹视图中呈现的图片浏览器无法看到任何照片。

所以我的建议是,当用户点击弹出窗口来查看photoBrowser时,您只需从viewController类中删除弹出窗口并显示photoBrowser,因为除此类以外,所有事情都是通过视图处理的。

我已经根据以上&的工作正常进行了修改,以您给出的代码为例,下载代码here并查看它。

让我知道它是否满足您的需求。

感谢

+0

是的,它的工作原理,但viewcontroller只显示在kgmodal和kgmodal不适合屏幕尺寸。在Iphone 4/4上,我无法看到导航栏中的整个dissmiss按钮以及Iphone 5上的整个视图底部和顶部的一些未填充位置。 – MasterRazer

+0

ü需要缩放包括导航栏在内的弹出视图并调整它们的大小。 – vishy

+0

怎么样?与自动化它不工作 – MasterRazer

0

我注意到这行代码:

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

我只能认为,既然是单身,它的UIApplication的重要窗口上添加contentView。如果是这种情况,那么模态视图控制器将始终在弹出窗口下方。您可以通过添加新的方法到KGModal

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

的方法应该显示指定控制器的视图弹出解决这个问题;您应该使用该方法。

编辑

一些更多的挖掘后,我发现KGModal显示在其他窗口的弹出。最快的解决方法是关闭弹出窗口,然后显示导航控制器。

+0

以及如何解雇? – MasterRazer

+0

我该如何解散弹出窗口并直接显示navcontroller? – MasterRazer

+0

实际上这是我真正的问题! http://stackoverflow.com/questions/13773682/subview-displays-wrong – MasterRazer