gpt4 book ai didi

ios - UIButton - NSInternalInconsistencyException - 无法使具有标识符 Cell2 的单元格出队

转载 作者:行者123 更新时间:2023-11-29 01:05:28 25 4
gpt4 key购买 nike

我有一个分割 View Controller 。在表格 View 中选择分割 View 。我在右栏按钮项目中有 UIButton 。当我点击 UIButton 时。我收到此错误 'NSInternalInconsistencyException',原因:'无法使具有标识符 Cell2 的单元出列 - 必须为标识符注册 Nib 或类,或者连接 Storyboard 中的原型(prototype)单元'

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

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

}

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

这是自定义类.h:

#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

这是自定义类.m:

#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

基本上,这个自定义类的作用是显示一个弹出窗口,其中包含一个表格 View 。

以下是弹出窗口内的表格 View 的生成方式:

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

现在,按下按钮后应用程序崩溃。有什么想法为什么我会收到此错误以及如何修复它吗?我脑子一片空白。

这是我的 cellForRowAtIndexPath 方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];

NSString *object = self.objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}

最佳答案

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

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

关于ios - UIButton - NSInternalInconsistencyException - 无法使具有标识符 Cell2 的单元格出队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com