我遇到了一个奇怪的错误...... 我有一个扩展另一个类的类,从中获取一些变量。这是一个非常简单的。 当我编译模拟器的代码时,它工作得很好。当我在Iphone中运行时,它会收到一个错误,指出没有设置vairable!代码: 父类标题:
#import <UIKit/UIKit.h>
#import "TarefaMap.h"
@interface GenericTarefaTableView : UITableViewController {
TarefaMap* tarefaMap;
TarefaMap* tarefaMapOriginal;
}
@property (nonatomic, retain) TarefaMap* tarefaMap;
@property (nonatomic, retain) TarefaMap* tarefaMapOriginal;
@end
父类实现:
#import "GenericTarefaTableView.h"
@implementation GenericTarefaTableView
@synthesize tarefaMap,tarefaMapOriginal;
@end
子类标题:
@interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
Tarefa* tarefa;
NSArray *fieldLabels;
UITextField *textFieldBeginEdited;
BOOL isEdit;
IBOutlet UITableViewCell *cell0;
IBOutlet UITextView* textView;
NSManagedObjectContext* context;
}
@property (nonatomic, retain) NSManagedObjectContext* context;
@property (nonatomic, retain) IBOutlet UITextView* textView;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell0;
@property (nonatomic, retain) Tarefa* tarefa;
@property (nonatomic, retain) UITextField* firstField;
@property (nonatomic, retain) NSArray *fieldLabels;
@property (nonatomic, retain) UITextField *textFieldBeingEdited;
@end
子类实现:
#import "EditTarefaViewController.h"
@implementation EditTarefaViewController
@synthesize tarefa, textFieldBeingEdited,firstField,fieldLabels,textView, cell0, context;
NSMutableArray *textFieldarray;
UIActionSheet *actionSheet;
UITableViewCell* cell1;
- (void)viewDidLoad
{
NSLog(@"ViewDidLoad");
[super viewDidLoad];
self.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
self.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
if ([tarefaMapOriginal isEqual:tarefaMap]) {
NSLog(@"SOMOS IGUAIS!!!!!");
}
NSLog(@"Comparando tarefas!!!!!");
if ([tarefaMapOriginal isEqualtoTarefaMap:tarefaMap]) {
NSLog(@"SOMOS IGUAIS2!!!!!");
}
}
这在模拟器上编译很好,但是当我尝试使用iPhone时,我收到一个错误,说变量tarefaMap未声明,应该在函数上声明......
有什么想法吗?
答案 0 :(得分:1)
@interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
在该行之前添加此
@class GenericTarefaTableView;
然后在.m文件中添加
import "GenericTarefaTableView.h"
并在viewdidload中更改
NSLog(@"ViewDidLoad");
[super viewDidLoad];
super.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
super.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
@implementation EditTarefaViewController
之前你必须导入TarefaMap.h并在EditTarefaViewController.h文件中声明这个,如下所示
@class TarefaMap;