在模拟器上继承工作,但不在iPhone上!
问题描述:
我遇到了一个奇怪的错误... 我有一个类扩展另一个,从它得到一些变量。它非常简单。 当我编译模拟器的代码时,它工作得很好。当我在Iphone上运行时,会出现一个错误,指出可放弃的内容没有设置!代码: 父类的头:在模拟器上继承工作,但不在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!!!!!");
}
}
这款C ompiles罚款在模拟器上,但是当我尝试在iPhone上,我得到一个错误说,变量tarefaMap是未申报的,并应在功能上声明...
任何想法?
答
@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
u必须导入TarefaMap.h,并在EditTaref中声明与aViewController.h文件中像这样
@class TarefaMap;
+0
嘿你有回复我 – 2011-04-01 15:41:18
尝试'[self.tarefaMapOriginal isEqual:方法self.tarefaMap]',也发布确切的错误和它发生什么线。这有帮助。 – 2011-04-01 13:37:38
这个问题可能来自于您的模拟器版本默认保护的变量以及您的iphone版本中的@private。这只是一个猜测,因为我不知道你会怎么做。 – 2011-04-01 13:38:36