Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]中的断言失败_Ios_Iphone_Objective C_Uitableview - Fatal编程技术网

Ios -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]中的断言失败

Ios -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]中的断言失败,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,由于某些原因,我的应用程序在尝试将单元格加载到tableview时失败。我在整个应用程序中的所有表视图都完全相同,我对它们没有任何问题。这可能与从另一个viewController初始化控制器有关吗?我不这么认为。故事板中的我的单元已获得标识符。这里是一个屏幕截图的链接 所以我什么都试过了,什么都没用 以下是使用[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]方法的输出: 20

由于某些原因,我的应用程序在尝试将单元格加载到tableview时失败。我在整个应用程序中的所有表视图都完全相同,我对它们没有任何问题。这可能与从另一个viewController初始化控制器有关吗?我不这么认为。故事板中的我的单元已获得标识符。这里是一个屏幕截图的链接

所以我什么都试过了,什么都没用

以下是使用[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]方法的输出:

2013-11-14 15:36:33.419 ComplyOS[43683:70b] *** Assertion failure in -[UITableView            dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:5261
2013-11-14 15:36:33.424 ComplyOS[43683:70b] *** Terminating app due to uncaught exception    'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ProcedureCell - must register a    nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000101fa9795 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000101d0c991 objc_exception_throw + 43
2   CoreFoundation                      0x0000000101fa961a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00000001018a99e9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4   UIKit                               0x00000001008f9879 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 150
5   ComplyOS                            0x00000001000099b4 -[EndoPxTableViewController tableView:cellForRowAtIndexPath:] + 116
6   UIKit                               0x0000000100902b8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
7   UIKit                               0x00000001008ea836 -[UITableView _updateVisibleCellsNow:] + 2297
8   UIKit                               0x00000001008fb381 -[UITableView layoutSubviews] + 207
9   UIKit                               0x0000000100892b27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10  QuartzCore                          0x00000001005afa22 -[CALayer layoutSublayers] + 151
11  QuartzCore                          0x00000001005a4589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12  QuartzCore                          0x00000001005a440a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13  QuartzCore                          0x0000000100519694 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
14  QuartzCore                          0x000000010051a70c _ZN2CA11Transaction6commitEv + 394
15  QuartzCore                          0x000000010051ad79 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
16  CoreFoundation                      0x0000000101f74ff7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17  CoreFoundation                      0x0000000101f74f67 __CFRunLoopDoObservers + 391
18  CoreFoundation                      0x0000000101f546d2 __CFRunLoopRun + 946
19  CoreFoundation                      0x0000000101f53f33 CFRunLoopRunSpecific + 467
20  GraphicsServices                    0x0000000103c2b3a0 GSEventRunModal + 161
21  UIKit                               0x0000000100837043 UIApplicationMain + 1010
22  Comply                              0x0000000100002703 main + 115
23  libdyld.dylib                       0x00000001029ed5fd start + 1
24  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException  
以下是我的UITableView控制器代码:

#import "EndoPxTableViewController.h"
#import <AFHTTPRequestOperationManager.h>
#import "ProcedureTableViewCell.h"

@interface EndoPxTableViewController (){}

@property (nonatomic, strong)NSArray *procedures;
@end

@implementation EndoPxTableViewController


- (void)setVisitItem:(Patient_VisitsModel *)visitItem{
if(_visitItem !=visitItem){
    _visitItem = visitItem;
     }
}

 -(void)setUserId:(NSString *)userId{
     if(_userId !=userId){
         _userId = userId;
    }
[self fetchProceduresData];
}


- (void) fetchProceduresData{
NSString *procedureURLString =[NSString stringWithFormat:@"https://XXXX";


AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:procedureURLString parameters:nil success:^(AFHTTPRequestOperation *operation, id json) {


    _procedures = json;
    [self.tableView reloadData];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error occured in getSessionID method");
    NSLog(@"Error: %@", error);

}];
 }

 - (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
 }

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Endoscopy Report";
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Procedures:%@", [_procedures valueForKey:@"description"]);
return _procedures.count;
 }

 - (ProcedureTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
static NSString *CellIdentifier = @"ProcedureCell";
ProcedureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *procedureDescription = [_procedures[indexPath.row] valueForKey:@"description"];
NSLog(@"Procedure Description:%@", procedureDescription);


cell.procedureLabel.text = procedureDescription;
cell.questionImage.image = nil;

return cell;
 }

#pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}

@end
#导入“intoExtableViewController.h”
#进口
#导入“ProcedureTableViewCell.h”
@接口OnExtableViewController(){}
@属性(非原子、强)NSArray*程序;
@结束
@ExtableViewController的实现
-(无效)设置就诊时间:(患者就诊时间模型*)就诊时间{
如果(_visitItem!=visitItem){
_VisiteTem=VisiteTem;
}
}
-(void)setUserId:(NSString*)userId{
如果(_userId!=userId){
_userId=userId;
}
[自取过程数据];
}
-(void)fetchProceduresData{
NSString*procedureURLString=[NSString stringWithFormat:@]https://XXXX";
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager];
[manager GET:procedureURLString参数:无成功:^(AFHTTPRequestOperation*操作,id json){
_过程=json;
[self.tableView重载数据];
}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“getSessionID方法中发生错误”);
NSLog(@“错误:%@”,错误);
}];
}
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
self.title=@“内窥镜检查报告”;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
NSLog(@“程序:%@,[_程序值forkey:@“说明”);
return _procedures.count;
}
-(ProcedureTableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“ProcedureCell”;
ProcedureTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString*procedureDescription=[\u PROCEDULES[indexPath.row]valueForKey:@“description”];
NSLog(@“过程描述:%@”,过程描述);
cell.procedureLabel.text=过程描述;
cell.questionImage.image=nil;
返回单元;
}
#pragma标记-导航
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
}
@结束

谢谢大家的帮助。我有点绝望了。

我的错!似乎您正在使用
dequeueReusableCellWithIdentifier:forIndexPath:
方法对单元格进行排队。请改为尝试
dequeueReusableCellWithIdentifier:
,它应该可以工作

dequeueReusableCellWithIdentifier:forIndexPath:
需要一个nib文件或一个注册的类来让单元格出列,但您使用的是情节提要原型单元格。如果您使用正确的标识符,
dequeueReusableCellWithIdentifier:
保证从情节提要返回单元格


希望有帮助。

我和你有同样的问题。 我发现了问题所在

在代码中

static NSString *CellIdentifier = @"ProcedureCell";
ProcedureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
当您在情节提要中的视图控制器之间使用segue时,应该使用“dequeueReusableCellWithIdentifier:forIndexPath:indexPath”方法(我在情节提要中说了“连接控制器”)

如果您只是使用Interface builder绘制自定义单元格,则必须使用如下方法

static NSString *CellIdentifier = @"ProcedureCell";
    ProcedureTableViewCell *cell = (ProcedureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[ProcedureTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

请尝试以下代码来配置自定义单元格

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

static NSString *cellIdentifier = @"ProcedureCell";

ProcedureTableViewCell *cell = (ProcedureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

// If there is no cell to reuse, create a new one
if(cell == nil) {
    cell = [[ProcedureTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

}
return cell;
}

似乎您正在为自定义单元格使用自定义类
ProcedureTableViewCell
。请确保您没有以某种方式在其内部替换单元格标识符。我在该类中所做的一切都是为label和UIImage分配IBOutlets。您是否将原型单元格的
class
设置为
ProcedureTableViewCell
.Is
ProcedureTableViewCell
UITableViewCell
的一个子类。Prototype确实有ProcedureTableViewCell类,如果UITableViewCell,它是一个子类。Prototype单元格的类应该从identity inspector设置为
ProcedureTableViewCell
,就像从您的设计Tada中一样……我已经尝试过了我不知道我做了什么不同,但是它加载了正确数量的单元格。现在我必须弄清楚为什么它不加载“过程描述”进入每个单元格。NSLog正在正常注销…@LKM我不确定什么不适合你,也不确定你的问题。我认为这个答案不是针对你的问题。谢谢。无返回cell@gowtham如果您使用的是故事板和原型单元,则它将返回一个单元,除非1。单元标识符不是s在故事板2中指定。单元标识符在故事板中指定,但在一些单独的VC和3中指定。代码中未使用相同的单元标识符(键入!)谢谢我的问题是解决原因是“我没有提到正确的tableView”