나는 전역 변수에 관한 여러 가지 게시물을 알고 있지만 아무 것도 도움이되지 않습니다. 내 문제는 - 내 AppDelegate.h에서 나는 두 변수 x와 y를 선언했다. 내를 ClassA에서 나는 AppDelegate.h 수입 및 추가 :IPhone : Objective C 전역 변수
AppDelegate mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
및 할당 값을 mainDelegate.x
및 mainDelegate.y
에. ClassB가에서
label1.text = mainDelegate.x;
label2.text = mainDelegate.y;
없음 오류로 이러한 x와 y를 할당하지만 null..nothing 레이블의 텍스트로 나타납니다.
사람이 도와주세요 수
..편집 : AppDelegate.h에서 :
@property (nonatomic, copy) NSString *x,*y;
mainDelegate.x=[[NSString alloc] initWithString:[homeArray objectAtIndex:indexPath.row]];
나는에서 얻을하려고이 mainDelegate.x ClassA.m에서 ClassB이며 null입니다.
x 및 y를 어떻게 선언 했습니까? 그들은 속성이 있습니까? – Abizern
일부 코드 스 니펫을 제공해주십시오. –
x 및 y를 AppDelegate.h에 선언했습니다. '@property (nonatomic, retain) NSString x, y;' – dinny