alertview textfieldのテキスト入力をNSMutableArrayにコピーしようとしましたが、alertviewがポップアップしてテキスト入力フィールドに入力しましたが、OKを押すと警告表示が消えますがここに私の可変配列UialertviewテキストをNSMutableArray、ios 4.3
にdoesntのコピーテキストがここに私のコード
-(IBAction)add:(UIButton *)sender
{
addCustomStand = [[NSMutableArray alloc] init];
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter a Stand Location"
message:@" "
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
UITextField *nameField = [[UITextField alloc]
initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
nameField.text = @"";
[dialog addSubview:nameField];
if ([nameField text]){
NSLog(@"Name Field %@ ",nameField.text);
[addCustomStand addObject:nameField.text];
}
[nameField release];
[dialog show];
[dialog release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"OK"])
{
NSLog(@"Button 1 was selected.");
NSLog(@"StandLocations %@ ",addCustomStand);
}
}
である私の出力は、誰もが間違っていただきまし助けることができる
2012-02-07 20:26:57.315 Avicii[1399:b603] Name Field
2012-02-07 20:26:59.720 Avicii[1399:b603] Button 1 was selected.
2012-02-07 20:26:59.721 Avicii[1399:b603] StandLocations (
""
)
ログ画面上にありますそのコードで?
名前フィールタグ= 100;ラインはそこにいますか? –
あなたのnameFieldにタグをつけているだけで、何でもかまいません。私は100を任意に選択します。あなたの名前フィールドには、サブビューに追加する前にタグ番号(100)を与えています。したがって、あなたのUIAlertViewデリゲートでは、 '[alertView viewWithTag:100]'を使ってnameFieldを取得できます。 –