Xcode 5多个错误,#import不导入头文件

时间:2014-05-07 08:13:12

标签: ios xcode

我正在努力实现一个搜索栏,用于搜索表格视图,我有很多错误。

Phrasebook.h

#import <Foundation/Foundation.h>

@interface Phrasebook : NSObject

@property (nonatomic, strong) NSString *name; //name of phrase
@property (nonatomic, strong) NSString *translation; //translation of name

@end

Phrasebook.m

#import "Phrasebook.h"

@implementation Phrasebook

@end

PhrasebookTableCell.h

#import <UIKit/UIKit.h>

@interface PhrasebookTableCell : UITableViewCell

@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *translationLabel;

@end

PhrasebookTableCell.m

#import "PhrasebookTableCell.h"

@implementation PhrasebookTableCell

- (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

有问题的.m文件的代码:

{
    static NSString *CellIdentifier = @"CustomTableCell";
    ERROR PhrasebookTableCell *cell = (PhrasebookTableCell *)[[self.tableView         dequeueReusableCellWithIdentifier:CellIdentifier]]; ERROR

    // Configure the cell...
    ERROR if (cell == nil) {
        cell = [[PhrasebookTableCell alloc] initWithStyle:UITableViewCellStyleDefault  

reuseIdentifier:CellIdentifier]; ERROR
    }

    // Display recipe in the table cell
    ERROR Phrasebook *phrasebook = [Phrasebook objectAtIndex:indexPath.row];
    cell.nameLabel.text = phrasebook.name;
    cell.translationLabel.text = phrasebook.translation;

    return cell; ERROR
}

错误:
1)解析问题:预期标识符
2)ARC语义问题:没有可见的@interface用于&#39; PhrasebookTableCell&#39;声明选择器&#39; initWithStyle:reuseIdentifier:&#39;
3)ARC语义问题:选择器没有已知的类方法&#39; objectAtIndex:&#39;
4)语义问题:Property&#39; nameLabel&#39;没有找到类型对象&#39; PhrasebookTableCell *&#39;
5)语义问题:属性&#39; translationLabel&#39;没有找到类型为&#39; PhrasebookTableCell *&#39;

的对象

1 个答案:

答案 0 :(得分:0)

在相关的.m文件的第3行中,当单个[[就足够时,您会有两个[括号。删除一个[]对,然后重试。

像这样:

PhrasebookTableCell *cell = (PhrasebookTableCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];