1

サーバーにテキスト値を保存しました。そのテキスト値を正常に取得し、ローカル データベース ファイルに保存しました。次に、その値を配列に追加しました。その配列値をUITextViewに表示すると。しかし、すべての値を表示するテキストビュー。インデックスをクリックするボタンがあります。最初のボタンをクリックすると、最初のテキストを表示する必要があります。次に、次のボタンの次へ。すべてのボタンをクリックすると、すべての値が表示されます。

コード:

-(void)dbClicked:(id)sender{


    [mmageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[productimg_array objectAtIndex:[sender tag]-1]]]]];


    [self.view addSubview:mmageView];
UITapGestureRecognizer *singletapp=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
    singletapp.numberOfTapsRequired=1;

    [mmageView addGestureRecognizer:singletapp];

}



- (void)singleTap:(UIGestureRecognizer *)singletap {

        UITextView *txt=[[UITextView alloc]initWithFrame:CGRectMake(50, 50, 150,150)];
                NSMutableString *string = [NSMutableString string];    

            for(int i=0;i<[descript_array count];i++){

                NSLog(@"descript array is  is %d",i);

      txt.text = [descript_array objectAtIndex:i];


              }

            [self.view addSubview:txt];

}

NSログ:

descript array is  is 14

string is the name is  image with black color
the name is image with black color
the name is image with white color
the name is 
the name is 
the name is 
the name is 
the name is 
the name is 
the name is 
the name is 
the name is 

descript array is  is 15

    string is the name is  image with black color
    the name is image with black color
    the name is image with white color
    the name is 
    the name is 
    the name is 
    the name is 
    the name is 
    the name is 
    the name is 
    the name is 
    the name is 
4

2 に答える 2

0

Forループのせいです。Forここでループを呼び出すのではなく、次のように値を引き出す必要があります。

txt.text = [descript_array objectAtIndex:i];

必要なのは、ボタン アクションの呼び出しを区別することです。つまり、どのボタンが押され、どの要素が配列から抽出されるかを区別するだけです。したがって、呼び出しを区別するために必要なのは、Gesture が実装されているイメージにタグを設定することだけです。タグは、次のようなジェスチャー コールを区別するのに役立ちます。

 [mmageView setTag: 10]; //Let say 10

Gesture デリゲート メソッドでは、次のようになります。

- (void)singleTap:(UIGestureRecognizer *)sender {

       if (sender.tag == 10) 
       {
             UITextView * yourTextView=[[[UITextView alloc]initWithFrame:CGRectMake(50, 50, 150,150)] autorelease];

             yourTextView.text = [descript_array objectAtIndex:10];  //give appropriate index to extract value

       }
            [self.view addSubview:txt];

}//End of method
于 2013-09-03T07:14:53.397 に答える