pLokie
pLokie

Reputation: 47

Reset several UILabels back to zero

I have numerous labels identified as

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; 

Now I know this is somewhat simple, But whats the best possible way to write this code when int Counter == 4, it will reset all the aforementioned labels back to zero within the code. Or do I change all the stored integer and float values back to 0? I have tried numerous If methods but it seems like it still not functioning right. Thank you for the help!

Upvotes: 0

Views: 38

Answers (1)

Konrad
Konrad

Reputation: 892

It would be easier if we had more of your code to know how complex what you want to do is. But I guess I would just do this, if I wanted "counter = 4" to reset all other stored ints to 0 and then the labels.

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

Upvotes: 1

Related Questions