2011-03-31 3 views
0

여러 함수 사이에 무언가를 정의하는 방법이 있습니까? 내가 정의 할 수 있지만 {} 밖에서는 사용할 수 없습니다. UITextField가 만든 코드의 텍스트를 가져올 수 있어야합니다. 내가 사용하고 아래의 코드는 다음과 UIAlertView 안에 텍스트 상자로 하여 myTextField을 정의하는 기능입니다함수간에 정의 유지하기

- (void)AlertShow32 { 

UIAlertView * alert = [[ [ UIAlertView alloc ] initWithTitle:@"The Most Annoying Button!" message:@"What's your name?" 
                delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil ]autorelease]; 
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
[myTextField setBackgroundColor:[UIColor whiteColor]]; 
[alert addSubview:myTextField];; 
// [myTextField release]; 
[alert show ]; 
} 

.

그러나 myTextField 텍스트를 나중에 코드에서 필요한 위치와 같이 나중에 함수에서 액세스 할 수있는 데이터로 저장할 수 있기를 원합니다. 이 도움 넣다

- (void)AlertShow33 { 

UIAlertView * alert = [[[[ UIAlertView alloc ] initWithTitle:@"The Most Annoying Button!" message:@"Nice to meet you %i, you have a wierd name!", myTextField.text ] 
                delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil ]autorelease]; 
alert.transform = CGAffineTransformTranslate(alert.transform, 0.0, 0.0); 
[alert show ]; 
} 

, 내가있는 다른 함수에서 다른 함수를 호출 :

만이 함수를 호출하는 부분입니다
if (Alerttime == 31) { 
     [self performSelector:@selector(AlertShow31) withObject:self afterDelay:0.01]; 
    } 

    if (Alerttime == 32) { 
     [self performSelector:@selector(AlertShow32) withObject:self afterDelay:0.01]; 
    } 

,하지만 난에 에게 Alerttime 정의 :

#define int *Alerttime; 
Alerttime = 0; 

누구나 내가 텍스트에 액세스하는 방법에 대한 아이디어가 있습니까 myTextField af 기능 은요?

답변

1

그게 무슨 속성이야. 당신의 시간 파일에서

, 인터페이스에 넣어 :

UITextField *myTextField; 

을 아래에 넣어 :

@property (nonatomic, retain) UITextField *myTextField; 

당신의 m 파일에서 구현 섹션의 시작에 넣어 :

@synthesize myTextField; 

그러면 self.myTextField (또는 동일한 이름의 로컬 변수가없는 경우 myTextField)로 액세스 할 수 있습니다. any 수업 중에 다른 곳.

그리고 Objective-C에 대한 좋은 소개 텍스트를 얻으려면 직접해야합니다. 너는 정말로 들어가고 있지만, 몇 가지 기본 사항은 빠져있다. 적성을 분명히 했으니 시간을 내서 철저히 구하십시오.

+0

아, 함수간에 코드 정의 된 객체의 텍스트를 유지하지 않을 것이라고 생각했는데, 각 함수가 기본값으로 시작한다고 생각했습니다. – cowbear16

+0

자기 선 사용에 대해 잊어 버렸습니다. 감사합니다. – cowbear16