2012-12-04 33 views
0

我在Alertview中有一個UITextField。現在我想在另一個函數中使用這個UITextfield值。 請看下面的代碼。如何在另一個函數中使用Alertview的UITextField值?

我Alertview代碼:

-(void)AlertView 
{ 
UIAlertView *alert = [[UIAlertView alloc] init]; 

alert.title = @"Used Defualt Name Or you Can Save Recoring With Your Own Name"; 
alert.message = @""; 
alert.delegate = self; 
[alert addButtonWithTitle:@"Cancel"]; 
[alert addButtonWithTitle:@"OK"]; 
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 82.0, 260.0, 25.0)]; 
[myTextField setBackgroundColor:[UIColor whiteColor]]; 
[alert addSubview:myTextField]; 
[alert show]; 
[alert release]; 

} 
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 

NSLog(@"name:%@ buttonID:%d",myTextField.text,buttonIndex); 
if (buttonIndex == 1) { 
    btnPlay.enabled=YES; 

    mySongname = myTextField.text; 
    NSLog(@"song name:%@ ",mySongname); 
} 
else { 
    btnPlay.enabled=YES; 
} 
} 

我聲明變量mysongname全球我的課,因爲我在同在那裏我有以下功能alertview在這裏使用它。

-(IBAction)playButton:(id)sender 
{ 
// [email protected]"my fourite songs"; 
    NSString *fina = [NSString stringWithFormat:@"%@",mySongname]; 
} 

現在在以上功能mysongname展現出來的範圍value.but當我刪除,我顯示上述功能的註釋然後正常工作。我不知道它爲什麼不通過這裏的UITextfield。

+0

嘗試設置屬性和合成到mySongname,以及使用self.mySongname = myTextField.text設定值; –

+0

現在感謝它的工作,當我根據你的說明進行設置。請在這裏回覆帖子,讓我接受它。 – jamil

+0

我發佈它作爲答案。 :-) –

回答

2

嘗試設置屬性併合成到mySongname,並使用self.mySongname = myTextField.text設置值;

+0

我爲您的問題添加了upvote。 –

+0

就像我爲你做的那樣 – jamil

0

只是聲明一個字符串對象並設置其值,並使用其值到警報視圖中的類

相關問題