0

我正在尝试将特定标签的文本从标签列表中解析到标签中的UIScrollView下一个视图中。但是这些标签文本来自NSMutableArray. 我试过了,但我只得到了参考的最后一个值,NSMutableArray请参阅以下代码:请建议我将做什么

-(void)dataPrinting
 {
int t= 60;


NSLog(@"%@",totalData);

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

    pplname=[[UILabel alloc]initWithFrame:CGRectMake(10, t, 200, 30)];
    pplname.backgroundColor=[UIColor clearColor];
    pplname.text=[totalData objectAtIndex:i];
    pplname.textColor=[UIColor redColor];

    [scrollView addSubview:pplname];

    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    //initWithFrame:CGRectMake(10, t, 200, 40) ];
    button.frame=CGRectMake(10, t, 200, 40);
    [button addTarget:self 
               action:@selector(nextview)
     forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:button];





           t=t+40;
  }

[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, t+2)];
[aview stopAnimating];

  }
-(IBAction)nextview
 {
   Details *detailsPage=[[Details alloc]initWithNibName:@"Details" bundle:nil];
    for (int i = 0; i < [totalData count]; i++)
  {        

   detailsPage.pplName=[totalData objectAtIndex:i];

 }



 [self presentModalViewController:detailsPage animated:YES];

}
4

1 回答 1

0

给标签以获取标签的特定名称只需用您的代码替换我的波纹管代码......

-(void)dataPrinting
     {
    int t= 60;


    NSLog(@"%@",totalData);

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

        pplname=[[UILabel alloc]initWithFrame:CGRectMake(10, t, 200, 30)];
        pplname.backgroundColor=[UIColor clearColor];
        pplname.text=[totalData objectAtIndex:i];
        pplname.tag = i;
        pplname.textColor=[UIColor redColor];

        [scrollView addSubview:pplname];

        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        //initWithFrame:CGRectMake(10, t, 200, 40) ];
        button.frame=CGRectMake(10, t, 200, 40);
        button.tag = i;
        [button addTarget:self 
                   action:@selector(nextview)
         forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:button];





               t=t+40;
      }

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, t+2)];
    [aview stopAnimating];

      }
    -(IBAction)nextview:(id)sender
     {
       UIButton *btnTemp = (UIButton*)sender;
       Details *detailsPage=[[Details alloc]initWithNibName:@"Details" bundle:nil];

       detailsPage.pplName=[totalData objectAtIndex:btnTemp.tag];

     [self presentModalViewController:detailsPage animated:YES];

    }
于 2012-11-02T07:43:11.683 回答