あなたは配列にテキストフィールドを追加し、ループ内でそのプロパティを変更することができます。
NSArray *textViews= [NSArray arrayWithObjects:textView1, textView2, textView3, nil];
for(UITextView *txtView in textViews)
txtView.text = [txtView.text stringByAppendingString:@"myAsciiString"];
[textViews release];
編集
どのtextViewがアクションを開始したのかを知りたい場合(複数のtextViewを接続していると仮定して同じIBActionに)、あなたが設定し、ビューのタグを確認したり、あなたがインスタンスと比較することができます可能性があり、次のいずれか
textView1.tag = 0;
textView2.tag = 1;
textView3.tag = 2;
//etc.
- (IBAction)someTextViewAction:(id)sender {
//Option 1
if (sender.tag == 0)
textView1.text = [textView1.text stringByAppendingString:@"myAsciiString"];
else if(sender.tag == 1)
textView2.text = [textView2.text stringByAppendingString:@"myAsciiString"];
else if(sender.tag == 2)
textView3.text = [textView3.text stringByAppendingString:@"myAsciiString"];
//Option 2
if ([sender isEqual:textView1])
textView1.text = [textView1.text stringByAppendingString:@"myAsciiString"];
else if ([sender isEqual:textView2])
textView2.text = [textView2.text stringByAppendingString:@"myAsciiString"];
else if ([sender isEqual:textView3])
textView3.text = [textView3.text stringByAppendingString:@"myAsciiString"];
}
あなたがアクティブなテキストビューに値を代入したい場合は、反復処理ができあなたのサブビューがあり、それが最初のレスポンダを持っている場合は、値を設定してください:
- (IBAction)someButtonAction:(id)sender {
for (UIView *view in self.subviews)
{
if ([view isKindOfClass:[UITextView class]])
{
if ([view isFirstResponder])
{
view.text = [view.text stringByAppendingString:@"myAsciiString"];
}
}
}
}
これは私のテキスト値を同時にすべてのビューに追加します。たぶん、私の質問を少し違う言葉にしていたはずです。 私はUITextViewが編集用にタップされていることを知りたいと思っています。上に挙げたIBActionを使用して、「アクティブなテキストビューのみ」というテキストを挿入し、それらのすべてには挿入しません。再度、感謝します! – Dan
あなたのコメントを反映するように更新されました。 – Jeremy
このアプローチ(オプション1)は、依然としてtrueと評価され、同時にすべてのテキストビューにテキストを挿入します。私はIB内の1つのボタンにアクションを割り当て、アクティブなテキストビューに基づいてテキストを挿入する必要があります。私はあなたの助けに感謝しますが、私はあなたの指示の中で何かを見逃すはずです。 – Dan