【发布时间】:2016-04-03 20:21:29
【问题描述】:
'无法将带有标识符 news 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者连接情节提要中的原型单元格'
#import "SidebarViewController.h"
#import "SWRevealViewController.h"
@interface SidebarViewController ()
@property (nonatomic, strong) NSArray *menuItems;
@end
@implementation SidebarViewController
NSArray *menuItems;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
//custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
menuItems = @[@"title", @"news ", @"comments", @"map", @"calendar", @"wishlist", @"bookmark", @"tag"];
}
- (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 menuItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
@end
标识符看起来像:
我能用这个做什么?
我正在尝试添加左侧滑动菜单,但是当我按下菜单按钮时它崩溃了。
【问题讨论】:
-
它们是静态单元格吗?如果没有,为什么你有这么多,除了文本和图像,这些单元格看起来都一样,应该在
cellForRowAtIndexPath中设置。如果它们是静态单元格,那么您不会将它们出列,它们就在那里。 -
@Paulw11 他们是原型细胞
-
你能展示你创建
SideBarViewController实例的代码吗? -
@Paulw11 SideBarViewController 的代码在上面完整版
-
是的,但是您是如何创建您正在展示的实例的?从一个赛格?你只是使用
alloc/init- 这是我的怀疑还是从情节提要中实例化了它。 ?
标签: ios objective-c iphone uitableview menu