当我单击视图控制器中显示的列表标签中的特定标签时,将标签文本削减到下一个视图

时间:2012-11-02 07:30:45

标签: iphone uibutton uilabel

我正在尝试将UIScrollView中显示的标签列表中的特定标签文本解析为标签中的下一个视图。但这些标签文本来自NSMutableArray。我试过但我只得到NSMutableArray的最后一个值参见以下代码参考:Plz建议我会做什么

-(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];

}

1 个答案:

答案 0 :(得分: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];

    }