【发布时间】:2011-04-01 12:50:05
【问题描述】:
我遇到了一个奇怪的错误... 我有一个扩展另一个类,从中获取一些变量。它是一个非常简单的。 当我为模拟器编译代码时,它工作得很好。当我在 Iphone 中运行时,它会收到一个错误,指出未设置变量!。编码: 父类头:
#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 未声明,应该在函数上声明...
有什么想法吗?
【问题讨论】:
-
试试
[self.tarefaMapOriginal isEqual:self.tarefaMap],另外,发布确切的错误以及它发生在哪一行。这有帮助。 -
问题可能源于在您的模拟器版本中默认为@protected 的变量,以及在您的iphone 版本中为@private 的变量。这只是一个猜测,因为我不知道你会怎么做。
标签: objective-c cocoa-touch ios inheritance xcode4