将几个 UILabel 重置为零
Reset several UILabels back to zero
我有很多标签被识别为
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 方法,但它似乎仍然无法正常工作。感谢您的帮助!
如果我们有更多你的代码来了解你想要做的事情有多复杂,那会更容易。但我想我会这样做,如果我想 "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];
}
我有很多标签被识别为
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 方法,但它似乎仍然无法正常工作。感谢您的帮助!
如果我们有更多你的代码来了解你想要做的事情有多复杂,那会更容易。但我想我会这样做,如果我想 "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];
}