显示XIB erorr nil

时间:2017-03-30 15:56:02

标签: ios objective-c view xib popover

我是Swift的新手,我开始学习XIB。我想按下按钮出现XIB。 我使用自由ARSPopover

我的错误:

  

警告:尝试出现    已经是   呈现(null)

我该如何解决这个问题?

我的按钮代码:

- (IBAction)btnShoPopover:(UIBarButtonItem *)sender {
    ARSPopover *popoverController = [ARSPopover new];
    popoverController.sourceView = self.view;
    popoverController.sourceRect = CGRectMake(370,0, 0, 0);
    popoverController.contentSize = CGSizeMake(200,300);
    popoverController.arrowDirection = UIPopoverArrowDirectionUp;

    [self presentViewController:popoverController animated:YES completion:^{
        [popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
            PopovViewController *poper = [[PopovViewController alloc] init];
            [self presentViewController:poper animated:YES completion:nil];

        }];
    }];
}

我的xib不下载:

enter image description here

我的xib控制器代码:

@interface PopovViewController ()
@end
@implementation PopovViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

我的控制器:

#import "ResourseTableViewController.h"
#import "ProbaViewController.h"

@interface ResourseTableViewController ()
@end

@implementation ResourseTableViewController 

@synthesize arrayOriginal;
@synthesize arForTable;

- (void)viewDidLoad {
    [super viewDidLoad];

    NSDictionary *dTmp=[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]];
    self.arrayOriginal=[dTmp valueForKey:@"Objects"];

    self.arForTable=[[NSMutableArray alloc] init] ;
    [self.arForTable addObjectsFromArray:self.arrayOriginal];

    SWRevealViewController *revealViewController = self.revealViewController;
    if ( revealViewController )
    {
        [self.sidebarButton setTarget: self.revealViewController];
        [self.sidebarButton setAction: @selector( revealToggle: )];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.arForTable count];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
    }
    [cell setIndentationLevel:[[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row];

    NSLog(@"Selected index data %@",d);

    if([d valueForKey:@"Objects"]) {
        NSArray *ar=[d valueForKey:@"Objects"];

        BOOL isAlreadyInserted=NO;

        for(NSDictionary *dInner in ar ){
            NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted=(index>0 && index!=NSIntegerMax);
            if(isAlreadyInserted) break;
        }

        if(isAlreadyInserted) {
            [self miniMizeThisRows:ar];
        } else {
            NSUInteger count=indexPath.row+1;
            NSMutableArray *arCells=[NSMutableArray array];
            for(NSDictionary *dInner in ar ) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [self.arForTable insertObject:dInner atIndex:count++];
            }
            [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}

- (IBAction)btnPopover:(id)sender {

    ARSPopover *popoverController = [ARSPopover new];
    popoverController.sourceView = self.view;
    popoverController.sourceRect = CGRectMake(370,0, 0, 0);
    popoverController.contentSize = CGSizeMake(200,300);
    popoverController.arrowDirection = UIPopoverArrowDirectionUp;

    [self presentViewController:popoverController animated:NO  completion:^{
        [popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
            ProbaViewController *poper = [[ProbaViewController alloc] init];
            CGFloat width = popoverPresentedSize.width;
            CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
            poper.view.frame = CGRectMake(0, 0, width, height);

            popover.view.layer.backgroundColor = [UIColor clearColor].CGColor;

            [popover.view addSubview:poper.view];
        }];
    }];
}

-(void)miniMizeThisRows:(NSArray*)ar{

    for(NSDictionary *dInner in ar ) {
        NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner];
        NSArray *arInner=[dInner valueForKey:@"Objects"];
        if(arInner && [arInner count]>0){
            [self miniMizeThisRows:arInner];
        }
        if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
            [self.arForTable removeObjectIdenticalTo:dInner];
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:
                                                    [NSIndexPath indexPathForRow:indexToRemove inSection:0]
                                                    ]
                                  withRowAnimation:UITableViewRowAnimationNone];
        }
    }
}
@end

1 个答案:

答案 0 :(得分:0)

Skimming the docs,看起来这个库对于弹出窗口中的内容非常通用。您的代码提供了一条线索,您希望在其中显示自定义视图控制器(PopovViewController)。

编辑让我们先找出问题所在。如果其他一切工作正常,那么这段代码应该显示一个绿色框...

[self presentViewController:popoverController animated:YES completion:^{
    [popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
        CGFloat width = popoverPresentedSize.width;
        CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
        UIView *test = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
        test.backgroundColor = [UIColor greenColor];
        [popover.view addSubview:test];
    }];
}];

如果可行,我们可以继续发现PopovViewController视图导致问题的原因。 (我的猜测是它的演示引发了一些与第三方库冲突的其他演示动画。

如果你得到一个没有警告或错误的工作绿色视图,请发布PopovViewController viewDidLoadviewWillAppear...didAppear,{{1}的代码等等