아래에 게시 된 클래스를 버튼 누름으로로드 할 때 오류가 발생합니다.식별자 태그가있는 셀을 큐에서 빼낼 수 없습니다.
코드는 슬라이드 아웃 메뉴를로드해야합니다. 이것은 내 문제를 일으키는 라인입니다. 나는 iOS/obj-c에 완전히 익숙하다. 이유는 모르겠지만 코드의이 줄은 _menuItems
배열의 각 항목에 대해 반복됩니다. NSLog는 배열의 각 항목을 출력하지만 다른 시간에 실행되어이 오류가 발생합니다. 적어도 내가 생각하는 것보다. 누군가가 나에게 몇 가지 조언을 해줄 수 있다면 감사 할 것입니다. 모든 것을 제외하고, 내 프로젝트는 두 가지 목표를 가지고 있습니다. 왜 그런지 모르겠고, 어떻게해야할지 모르겠고, 어떻게 변경해야할지 모르겠다. 그게 문제일까요?
013-11-28 12:11:31.902 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.908 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.911 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.917 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.921 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.924 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.929 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.931 DatabaseTest[57858:a0b] The code runs through here!
2013-11-28 12:11:31.932 DatabaseTest[57858:a0b] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:5261
2013-11-28 12:11:31.936 DatabaseTest[57858:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier tag - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
콘솔 출력이 있습니다.
#import "SidebarViewController.h"
#import "SWRevealViewController.h"
@interface SidebarViewController()
@property (nonatomic, strong) NSArray *menuItems;
@end
@implementation SidebarViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.2f alpha:1.0f];
self.tableView.backgroundColor = [UIColor colorWithWhite:0.2f alpha:1.0f];
self.tableView.separatorColor = [UIColor colorWithWhite:0.15f alpha:0.2f];
_menuItems = @[@"title", @"news", @"comments", @"map", @"calendar", @"wishlist", @"bookmark", @"tag"];
}
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
destViewController.title = [[_menuItems objectAtIndex:indexPath.row] capitalizedString];
if ([segue isKindOfClass: [SWRevealViewControllerSegue class]]) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [self.menuItems objectAtIndex:indexPath.row];
NSLog(@"The code runs through here!");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
@end
그 중 하나/또는 : 클래스 또는 펜촉 인 경우 등록하면 셀을 확인하지 않아도됩니다! = nil. –
내가 사용하고있는 코드는 작동하는 예제에서 가져온 것이므로, 왜 그렇게 과감한 변경이 필요한지 알 수 없습니다. 질문에서 프로젝트에 어떻게 든 두 가지 목표가 있다고 언급했는데,이 문제를 어떻게 든 유발할 수 있습니까? – Killian
해결 방법 : 1. NSString * CellIdentifier가 nil이 아닌지 확인하십시오. 사용 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier : CellIdentifier]; 대신 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier : CellIdentifier forIndexPath : indexPath]; –