IOS自定义tableView:没有可见的@interface用于' XYZCustomCell'声明选择器' initWithStyle:reuseIdentifier:'

时间:2014-12-18 03:39:58

标签: ios uitableview custom-cell

我正在尝试完成本教程:http://zeroheroblog.com/ios/how-to-create-simple-tableview-with-custom-cells

我在这个功能的最后被困住了:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    XYZCustomCell *cell = (XYZCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(cell == nil)
    {
        cell = [[XYZCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    XYZTextFieldFormElement *item = [self.formItems objectAtIndex:indexPath.row];
    cell.labelField.text = item.label;
    cell.valueField.delegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

在这一行: cell = [[XYZCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 我在主题标题中写了错误。

此外,找不到labelField和valueField。这是XYZCustomCell.m和.h:

//  XYZCustomCell.m
#import "XYZCustomCell.h"

@implementation XYZCustomCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

//  XYZCustomCell.h
#import <UIKit/UIKit.h>

@interface XYZCustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UITextField *valueField;
@property (weak, nonatomic) IBOutlet UITextField *labelField;

@end

我非常确定已正确遵循教程的步骤。你知道错误的来源吗?

谢谢

1 个答案:

答案 0 :(得分:0)

我在类之前进行了重构以删除所有XYZ前缀并且它有效...