Objective c 为什么我的原型细胞显示为空白?

Objective c 为什么我的原型细胞显示为空白?,objective-c,ios,xcode,uistoryboard,Objective C,Ios,Xcode,Uistoryboard,在我的故事板的uitableview中,我定义了一个原型单元。在该单元格(自定义类kzTexturedCellv2)中,我有一个文本视图和一个图像视图。我还为单元格指定了一个标识符(“kzTexturedCellv2”),并使用 创建单元格。问题是单元格显示为空(没有我在storyboad中添加的任何子视图)。当我尝试在单元格内设置uitextview的文本时,它总是返回null。这是怎么回事?当使用故事板时,不需要对单元格进行alloc初始化 看 仅限使用: kzTexturedCellv2

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


创建单元格。问题是单元格显示为空(没有我在storyboad中添加的任何子视图)。当我尝试在单元格内设置uitextview的文本时,它总是返回null。这是怎么回事?

当使用故事板时,不需要对单元格进行alloc初始化

仅限使用:

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

Alloc init将由框架处理

当使用故事板时,不需要Alloc init单元

仅限使用:

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

Alloc init将由框架处理

您可以看到以下代码吗。我希望这对你有帮助

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

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

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

别忘了在字符串中添加符号AND别忘了在字符串中添加符号AND