gpt4 book ai didi

objective-c - 在 ViewPicker 中选择行

转载 作者:行者123 更新时间:2023-11-29 04:20:39 25 4
gpt4 key购买 nike

在 viewDidLoad 中我有这段代码:

// Here is always shown the correct string aCapital value one, two, three, four

NSLog(@"资本%@", self.aCapital);

if (!self.aCapital) {
self.aCapital = @"One";
} else {

if (self.aCapital = @"One") {
[self.Select selectRow:0 inComponent:0 animated:NO];
NSLog(@"One");
return;
}

if (self.aCapital = @"Two") {
[self.Select selectRow:1 inComponent:0 animated:NO];
NSLog(@"Two");
return;
}

if (self.aCapital = @"Three") {
[self.Select selectRow:2 inComponent:0 animated:NO];
NSLog(@"Three");
return;
}

if (self.aCapital = @"Four") {
[self.Select selectRow:3 inComponent:0 animated:NO];
NSLog(@"Four");
return;
}

}

但是 Select PickerView 未显示正确的 selectRow。如果我删除所有代码并在 viewDidLoad 中我只需插入

[self.Select selectRow:2 inComponent:0 animated:NO];

显示了正确的三行(对于一值和二值而言相同)。相反,使用 selectRow:3 不会显示四,而是显示一个!

最佳答案

这行代码会产生问题 if (self.aCapital = @"One") 您正在 if 语句内分配值。此表达式的计算结果始终为 true

您需要使用

比较这些值
if (self.aCapital == @"One")

if ([self.aCapital isEqualToString: @"One"])

关于objective-c - 在 ViewPicker 中选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13024690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com