UIButton - NSInternalInconsistencyException - 无法使用标识符Cell2对单元格进行出列

时间:2016-04-05 18:51:55

标签: ios objective-c uitableview uibutton

我有一个拆分视图控制器。在拆分视图的表视图选择中。我在正确的栏按钮项目中有UIButton。当我点击UIButton时。我收到此错误 var menu = document.querySelector('<put direct parent of lists here (ex: .menu)>'); var anchors = menu.getElementsByTagName('li'); for (var i = 0; i < anchors.length; i += 1) { anchors[i].addEventListener('click', function() { clickHandler(anchors[i]) }, false); } function clickHandler(anchor) { var hasClass = anchor.getAttribute('class'); if (hasClass !== 'active') { anchor.setAttribute('class', 'active'); } }

现在按下按钮时,会发生以下情况:

'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell2 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

communityPopup是一个名为PopupGenerator的自定义类

这是自定义类.h:

- (IBAction)selectCommunityPressed:(id)sender {
    if(!communitiesSorted)
    {
        [self CustomAlert:@"Sorry no data received, if VPN and 3G/Wifi are working, please press the back button and try again, else contact software vendor."];
        return;
    }

    if(communityPopup)
        [[communityPopup getPopOver]presentPopoverFromRect:_selectCommunity.bounds inView:_selectCommunity permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

这是自定义类.m:

#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"

@interface PopupGenerator : NSObject 

@property (nonatomic,strong) UIViewController *popview;
@property (nonatomic,strong) UIPopoverController *popover;

-(PopupGenerator *)initWithFrame:(CGRect) frame;

-(void)addItemToPopUp:(id)item;

-(UIPopoverController *)getPopOver;

-(UIViewController *)getPopView;

@end

这个自定义类所做的是一个弹出窗口,里面有一个表视图。

以下是如何生成弹出窗口中的tableview:

#import "PopupGenerator.h"

@implementation PopupGenerator
@synthesize popover;
@synthesize popview;

-(PopupGenerator *)initWithFrame:(CGRect) frame
{
    self = [super init];

    if(self)
    {
        popview=[[UIViewController alloc] init];
        [popview.view setBackgroundColor:[UIColor whiteColor]];
        [popview.view setFrame:frame];
        popover=[[UIPopoverController alloc] initWithContentViewController:popview];

    }

    return self;
}
-(void)addItemToPopUp:(id)item
{[popview.view addSubview:item];}
-(UIPopoverController *)getPopOver
{return popover;}
-(UIViewController *)getPopView
{return popview;}



@end

现在,按下按钮后应用程序崩溃了。任何想法为什么我收到此错误以及如何解决它?我的想法是空白的。

这是我的cellForRowAtIndexPath方法

- (void)WaitUntilAreaSort
{
    if([areaData.communityDictionary count]!=0 && areaData.communityDictionary!=nil)
    {
        selectedAreaTable = [[UITableView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 350.0f, 395.0f) style:UITableViewStylePlain];
        [selectedAreaTable setBounces:NO];
        selectedAreaTable.delegate = self;
        selectedAreaTable.dataSource = self;
        NSArray *unsortedAreaData = [areaData.communityDictionary valueForKey:[[areaData.communityDictionary allKeys] objectAtIndex:0]];
        if (unsortedAreaData == (id)[NSNull null])
            [self CustomAlert:@"Error downloading data, please contact software vendor for assistance"];
        else
        {
            sortedAreaData = [[NSArray alloc]initWithArray: [unsortedAreaData sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]];
            communityPopup = [[PopupGenerator alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 350.0f, 540.0f)];
            [communityPopup getPopOver].popoverContentSize = CGSizeMake(350.0f, 540.0f);
            [communityPopup addItemToPopUp:selectedAreaTable];

            UILabel *sortLabel = [[UILabel alloc]initWithFrame:CGRectMake(115, 395, 120, 30)];
            [sortLabel setFont:[UIFont fontWithName:@"Helvetica" size:17]];
            [sortLabel setTextAlignment:NSTextAlignmentCenter];
            [sortLabel setTextColor:[UIColor whiteColor]];
            [sortLabel setBackgroundColor:[UIColor clearColor]];
            [sortLabel setText:@"Sort By:"];
            [communityPopup addItemToPopUp:sortLabel];
            sortLabel = nil;

            sortCriteria = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Alphabetical",@"Closing Date", nil]];
            [sortCriteria setFrame:CGRectMake(50, 430, 250, 35)];
            [sortCriteria setSelectedSegmentIndex:0];//alphabetical order
            [sortCriteria addTarget:self action:@selector(SortCriteriaChanged:) forControlEvents:UIControlEventValueChanged];
            [sortCriteria setBackgroundColor:[UIColor clearColor]];

            NSUserDefaults *communityPrefs = [NSUserDefaults standardUserDefaults];
            NSString *alpha = [communityPrefs objectForKey:@"isAlphabeticalSort"];

            if([alpha  isEqual: @"YES"])
            {
                sortCriteria.selectedSegmentIndex = 0;
            }
            else
            {
                sortCriteria.selectedSegmentIndex = 1;
            }


            [communityPopup addItemToPopUp:sortCriteria];

            selectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(50.0f, 465.0f, 250.0f, 30.0f)];
            [selectionLabel setTextAlignment:NSTextAlignmentCenter];
            [selectionLabel setTextColor:[UIColor blueColor]];
            [selectionLabel setBackgroundColor:[UIColor clearColor]];
            [selectionLabel setText:@""];
            [communityPopup addItemToPopUp:selectionLabel];

            selectedAreaOKButton =[UIButton buttonWithType:UIButtonTypeCustom];
            selectedAreaOKButton.frame = CGRectMake(125.0f,495.0f,105.0f, 37.0f);
            [selectedAreaOKButton setBackgroundColor:[UIColor whiteColor]];
            [selectedAreaOKButton setTitle:@"OK" forState:UIControlStateNormal];
            [selectedAreaOKButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            [selectedAreaOKButton addTarget:self action:@selector(SelectedAreaOKButtonPressed:)forControlEvents:UIControlEventTouchUpInside];
            [communityPopup addItemToPopUp:selectedAreaOKButton];

            if([[areaData.communityDictionary allKeys]count] != 0)
                communitiesSorted = true;
        }
    }
    [_selectCommunity setEnabled:YES];
    [self StopActivityIndicator];
}

1 个答案:

答案 0 :(得分:1)

您能告诉我们您的cellForRowAtIndexPath方法吗?

您可能忘记在故事板中包含单元格标识符或设置单元格的类。