移动UIButton后文字不可见

问题描述:

float newY = 0; 
CGRect buttonFrame; 
for(int i=1; i<=countTabItems;i++){ 
    id item = [self viewWithTag:i]; 
    if([item isKindOfClass:[UIButton class]]){ 
     UIButton *button = item; 
     [item release]; 
     NSLog(@"got %@", button.titleLabel.text); 
     buttonFrame = button.frame; 
     buttonFrame.size.height = self.frame.size.height/countTabItems; 
     buttonFrame.size.width = self.frame.size.width; 
     buttonFrame.origin.x = 0; 
     buttonFrame.origin.y = newY; 

     button.frame = buttonFrame; 
     [button setTitle:@"TEST" forState:UIControlStateNormal]; 
     NSLog(@"%0.2f",newY); 
     [button release]; 
     newY += frame.size.height/countTabItems; 
    } 
} 

有人可以告诉我这段代码有什么问题吗?我使用它来移动按钮从原来的位置后,UIButton没有显示任何标题(文本)。移动UIButton后文字不可见

[self viewWithTag:i];不保留任何内容,因此项目对象的发布不应该在那里。这同样适用于释放按钮对象。尝试删除这两个版本,看看它是否可以解决您的问题。

+0

这工作:)非常感谢。 – Anand 2012-03-11 10:20:41