为什么我的原型单元格显示空白?

在我的故事板中的一个可用视图中,我定义了一个原型单元格。 在该单元格(自定义类kzTexturedCellv2)我有一个文本视图和图像视图。 我也给了单元格一个标识符(“kzTexturedCellv2”)并使用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { kzTexturedCellv2 *cell = [[kzTexturedCellv2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kzTexturedCellv2"]; ... 

创造细胞。 问题在于单元格显示为空白(没有添加到storyboad中的任何子视图)。当我尝试在单元格内设置uitextview的文本时,它总是返回null。 这里发生了什么?

当使用故事板时,不需要分配init单元。

请参阅为原型单元更改dequeueReusableCellWithIdentifier行为?

仅使用:

 kzTexturedCellv2 *cell = [tableView dequeueReusableCellWithIdentifier:@"kzTexturedCellv2"]; 

Alloc初始化将由框架处理

你能看到下面的代码。 我希望这对你有帮助

 - (void)viewDidLoad{ [super viewDidLoad]; // Create your image UIImage *image = [UIImage imageNamed: @"person_menu.png"]; UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil]; // set the text view to the image view self.navigationItem.leftBarButtonItem = barButton; menuItems = @[@"title", @"Payment", @"History",@"BookNow",@"Help", @"Promotions",@"Notifications", @"Settings", @"logOut"]; } #pragma mark #pragma mark - UITableViewDelegate Methods - (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]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == 0) { return 140; }else{ return 75; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.highlighted = YES; return cell; } 

你有什么在UITableviewCell中的标识符可以收集这些标识符并将其添加到一个NSArray中

因为你是这种情况,你可以像这样使用::

 kzTexturedCellv2 *cell = [tableView dequeueReusableCellWithIdentifier:@"kzTexturedCellv2"];