将多个UILabel重置为零

时间:2015-04-09 15:41:52

标签: ios uilabel

我有很多标签标识为

int counter;
int largeCount;
int lowCount;
int cardCount;
int mButton;
int totalCount;


IBOutlet UILabel *counterLabel;
IBOutlet UILabel *largeCards;
IBOutlet UILabel *lowCards;
IBOutlet UILabel *totalCards;
IBOutlet UILabel *work;
IBOutlet UILabel *pCount;   
IBOutlet UILabel *tCount; 

现在我知道这有点简单,但是当int Counter == 4时,最好的方法是编写这段代码,它会在代码中将所有上述标签重置为零。或者我将所有存储的整数和浮点值更改回0?我尝试了很多If方法,但似乎它仍然无法正常工作。谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

如果我们有更多的代码来了解您想要做的事情有多复杂,那会更容易。但我想我会这样做,如果我想要" counter = 4"将所有其他存储的整数重置为0,然后重置标签。

- (void) verifyCounterAndUpdateLabels
{
switch(self.counter)
    {
        case 4:
            self.largeCount = 0;
            self.lowCount = 0;
            self.cardCount = 0;
            self.mButton = 0;
            self.totalCount = 0;
            break;
    }

[self updateLabels];

}

- (void) updateLabels
{
    self.counterLabel.text = [NSString stringWithFormat:@"%d", self.counter];
    self.largeCards.text = [NSString stringWithFormat:@"%d", self.largeCount];
    self.lowCards.text = [NSString stringWithFormat:@"%d", self.lowCount];
    self.totalCards.text = [NSString stringWithFormat:@%d", self.cardCount];

    // I don't know what this label should refer to
    //self.work.text = [NSString stringWithFormat: @"%d", variable];
    self.pCount.text = [NSString stringWithFormat: @"%d", self.mButton];
    self.tCount.text = [NSString stringWithFormat: @"%d", self.totalCount];
}