显示 XIB errorr nil

Display XIB erorr nil

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

我的错误:

Warning: Attempt to present on which is already presenting (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没有下载:

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

Skimming the docs,就弹出窗口中显示的内容而言,该库看起来非常通用。您的代码提供了您希望在其中呈现自定义视图控制器的线索 (PopovViewController)。

EDIT 先看看问题出在哪里。如果其他一切正常,那么这段代码应该显示一个绿色框...

[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 的观点造成问题的原因。 (我的猜测是它的演示触发了一些与第 3 方库冲突的其他演示动画。

如果您得到一个没有警告或错误的工作绿色视图,post PopovViewController 的代码 viewDidLoadviewWillAppear...didAppear...didLayout