私はIOSアプリケーションを開発しています。私は、動的テキストフィールドやボタンを作成しています、と私は、ボタンをクリックしたときに、テキストフィールドのテキストを取得したいが、私はエラーを取得しています:ボタンをクリックしてTextFieldテキストを取得する
- (IBAction)customFieldAdd:(id)sender{
[_addfieldArray addObject:_field];
x = 10;
y = 10;
for(int i = 0; i < [_addfieldArray count]; i++) {
UITextField *copyfield = [[UITextField alloc]initWithFrame:CGRectMake(5.0, x + _field.frame.size.height, 195.0f, 30.0f)];
[copyfield setDelegate:self];
[copyfield setTag:i];
[_filterPossibleValueView addSubview:copyfield];
x = x+_field.frame.size.height+10;
UIButton *copyAddButton = [[UIButton alloc]initWithFrame:CGRectMake(202.0f, y + _addField.frame.size.height, 30.0f, 30.0f)];
[copyAddButton setTag:i];
[copyAddButton addTarget:self action:@selector(customFieldDelete:) forControlEvents:UIControlEventTouchUpInside];
[_filterPossibleValueView addSubview:copyAddButton];
y = y+_addField.frame.size.height+10;
count++;
}
}
- (IBAction)customFieldDelete:(id)sender{
UIButton *button = (UIButton*)sender;
NSInteger index = button.tag;
// [_addfieldArray removeObjectAtIndex:index];
UITextField *field = [_filterPossibleValueView viewWithTag:index];
NSString *myText = field.text;
}
あなたがボタンで指定したタグで間違いが解決された場合は、問題を解決します – iPatel
'UITextField * field = [_filterPossibleValueView viewWithTag:index];'このコード行は、 'UITextField'ではなく' UIView'を返しています。あなたのタグを確認してください。 – iPeter