在顶部显示 navigationController [英] Display navigationController on top

查看:17
本文介绍了在顶部显示 navigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中设置了一个子视图弹出窗口",如果用户点击子视图弹出窗口上的按钮,我想显示一个 navController.到目前为止,我已经设置了按钮,但是如果我点击按钮,navigationController 会出现在我的弹出窗口下!?我已经搜索了一些解决方案,但我没有找到任何解决方案.整个控制器实际上显示在一个文件夹中,您可以在这里找到: 实现了这个功能,看看吧.

我使用了相同的 KGModal 示例代码,并根据要求进行了扩展.我使用 Xib 来查看带有导航栏的视图.

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

[[KGModal sharedInstance] hideAnimated:YES];

更新:

在文件夹视图中显示照片浏览器的原因是,您试图在文件夹视图中显示照片浏览器,因此它在高度非常小的文件夹视图中显示.看不到任何照片.

所以我的建议是,当用户点击弹出窗口以查看 photoBrowser 时,您只需从 viewController 类中删除弹出窗口并呈现 photoBrowser,因为除了这个类之外,所有内容都通过视图处理.

我已按照上述进行了更改 &工作正常,你给的代码,下载代码这里和看看吧.

如果它满足您的需求,请告诉我.

谢谢

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:

The folder itself:

The popup:

Thanks in advance.

解决方案

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

这篇关于在顶部显示 navigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆