移动UIButton后文本不可见

时间:2012-03-11 10:09:58

标签: ios objective-c iphone 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没有显示任何标题(文本)。

1 个答案:

答案 0 :(得分:1)

[self viewWithTag:i];不会保留任何内容,因此项目对象的释放不应该存在。对于按钮对象的释放也是如此。尝试删除这两个版本,看看它是否解决了您的问题。