ここにテキストフィールドを含むアラートビューのコードを実装しました。[OK]ボタンをクリックすると、入力したテキストフィールドの値が文字列形式で(str)として格納され、配列をテーブルビューにロードするために、その値を配列に追加しますが、ここでの問題は、テーブルビューが1つのアイテムで構成されるたびですが、アラートからアイテムを入力する複数のアイテムを保存し、それを配列アイテムとして保存したいのですが、アラートビューを介して複数の配列アイテムを保存するためのコードを実装する方法は、iphoneでこの問題を解決するのに役立ちます。
myAlert = [[UIAlertView alloc] initWithTitle:@"Enter year"
message:@"alert message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[myAlert addTextFieldWithValue:@"" label:@"entervalue"];
alertTextField=[myAlert textFieldAtIndex:0];
alertTextField.keyboardType=UIKeyboardTypeAlphabet;
alertTextField.clearsOnBeginEditing=YES;
alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
[myAlert show];
[myAlert release];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Ok"]) {
str = alertTextField.text;
[savedarray addObject:str];
}
}