开发者

Change lable text in uitablecell

I want to implement tablecell in which there is one label with text = 0 and two button with text '+' and '-'

  • when i click + button then i want to increment text label by one.
  • when i click - button then i want to decrem开发者_JAVA技巧ent text label by one.

Any idea how to change the label of uitablecell.

Thanks in advance.


- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier{
    UIButton * mp;
    UILabel *l1;  
    UITableViewCell *cell=[[[UITableViewCell alloc]initWithFrame: CGRectMake(0, 0, 300, 60) reuseIdentifier:nil] autorelease];  
    l1=[[UILabel alloc] initWithFrame:CGRectMake(100.0, 15.0, 400.0, 40.0)];  
    l1.tag=1;  
    l1.font=[UIFont fontWithName:@"AppleGothic" size:17];  
    l1.textColor=[UIColor blackColor];  
    l1.backgroundColor=[UIColor clearColor];  
    l1.numberOfLines=3;  
    [cell.contentView addSubview:l1];  
    [l1 release]; 

mp=[[UIButton alloc] initWithFrame:CGRectMake(250, 25, 50, 20)];
mp.tag=2;
mp.font=[UIFont boldSystemFontOfSize:14];
mp.textColor=[UIColor blueColor ];
[mp addTarget:self  action:@selector(mapbtnpressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mp];
[mp release] 
        return cell;  
}  

in a cellForRowAtIndexPath method u call

cell=[self getCellContentView:CellIdentifier];  
labelname=(UILabel *)[cell viewWithTag:1];  

    [cell.contentView addSubview:labelname];  

click event  
+  
    labelname.text=[NSString stringWithFormat:@"%d",[lanename.text intvalue]+1];    
-event   
  labelname.text=[NSString stringWithFormat:@"%d",[lanename.text intvalue]-1];  


Look at this page of documentation. Especially, Listing 5-3. The basic idea is that all custom subviews should be added to contentView of your table cell.


Try using setText: method of UILabel

[urLabel setText:newText];

- (IBAction)plusButtonPressed
{
int value = [urLabel.text intValue];
value++;
[urLabel setText:[NSString stringWithFormat:@"%d",value]];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜