gpt4 book ai didi

ios - 更新 objective-c 中的多个标签

转载 作者:行者123 更新时间:2023-12-01 19:57:03 25 4
gpt4 key购买 nike


@interface ViewController ()
@property (nonatomic,strong) NSMutableArray * gameB;
@property (nonatomic,strong) NSMutableArray * rows;
- (IBAction)initialize:(id)sender;
- (BOOL) isEmpty;
@end

- (IBAction)startGme:(id)sender {
_rows = [[NSMutableArray alloc] initWithCapacity:4];
_gameB = [[NSMutableArray alloc]initWithObjects :_rows , _rows ,_rows ,nil];
}

`

This is how my storyboard would look. These all values update from a 2-D array.我是 objective-c 的新手。我想要做的是每次我的数组发生变化时更新一些标签。
我知道如何更新一个标签。但是,如果标签的数量不止一个,是否有一种通用的方法可以做到这一点,所以每次我的数组中的值发生变化时,我的标签都会得到更新,或者我需要更新每个标签的硬代码?
任何引用代码都会有所帮助。

最佳答案

只需遍历数组并设置标签。

[yourArray enumerateObjectsUsingBlock:^(id x, NSUInteger index, BOOL *stop){
UILabel *label = (UILabel*)[self.view viewWithTag:index];
NSString *str = (NSString*)x;
[label setText:x];
}];

这假设您的标签具有标签集 0-(标签数量),并且您的数组包含 NSString。

关于ios - 更新 objective-c 中的多个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41888934/

25 4 0