使用Class1中的NSString变量作为类2上的UILabel
我有一个问题是一个非常基本的情况。 从今天早上开始,我读了很多关于它的书,但没能把它付诸实践 我从一个UIPicker获取一个名称,并希望在另一个视图中展示这个名称,基本上,在另一个类中使用一个类中的一个变量 这是关于这个问题的主要声明 ViewController.h使用Class1中的NSString变量作为类2上的UILabel,class,nsstring,instance,Class,Nsstring,Instance,我有一个问题是一个非常基本的情况。 从今天早上开始,我读了很多关于它的书,但没能把它付诸实践 我从一个UIPicker获取一个名称,并希望在另一个视图中展示这个名称,基本上,在另一个类中使用一个类中的一个变量 这是关于这个问题的主要声明 ViewController.h @interface ViewController : UIViewController { IBOutlet UIPickerView *pickerAlunos; NSMutableArray *arrayA
@interface ViewController : UIViewController
{
IBOutlet UIPickerView *pickerAlunos;
NSMutableArray *arrayAlunos;
NSString *alunoAtual;
}
- (IBAction)botaoSelecionado:(UIButton *)sender;
- (void)definaAluno:(NSString*)oNome;
@property (nonatomic, retain) IBOutlet UIPickerView *pickerAlunos;
@property (nonatomic, retain) NSMutableArray *arrayAlunos;
@property (nonatomic, retain) NSString *alunoAtual;
@end
在ViewController.m上,我用definaAluno定义了它:
- (void)definaAluno:(NSString*)oNome {
oNome = self.alunoAtual;
}
- (IBAction)botaoSelecionado:(UIButton *)sender; {
NSInteger linha = [pickerAlunos selectedRowInComponent:0];
NSString *selecionado = [arrayAlunos objectAtIndex:linha];
self.alunoAtual = selecionado;
}
所以,在另一个类ELTDDimensions.m上,我使用lazy声明初始化它,但它返回null
- (ViewController *)student {
if(!student) {
student = [[ViewController alloc] init];
}
return student;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.studentLabel.text = self.student.alunoAtual;
}
最后一行得到一个空值。
studentLabel和student在ELTDimension.h上正确声明为
ViewController *student;
IBOutlet UILabel *studentLabel;
有人能帮我吗