gpt4 book ai didi

ios - 我想将 UISegmentedControl.selectedSegmentIndex 保存在核心数据中 - 但如何

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

我使用分段控件作为联系人应用程序的一种单选按钮系统。有三个按钮,问题是联系人是否是现有客户。按钮的名称为“否”、"is"、“其他部门”

我在开发 iOS 方面完全是新手,而这个正在拔掉我最后的白发

我希望能够将 selectedSegmentIndex 值保存在核心数据的数据库中,这样我就可以在下一个 View 上正确显示状态 - 但我真的很难理解如何保存该值:

if (self.existCustSelection.selectedSegmentIndex == 2)
[self.currentContact setExistCust:[existCustSelection stringWithFormat:@"%d", @"2"]];

- 这会产生

的编译错误

No visible @Interface for 'UISegmentedControl' declares the selector 'stringWithFormat:'

我确实明白 - 我的问题是,我想设置 existCust 而不是 existCustSelection,但无论出于何种原因,我在编写过程中都没有得到该选项代码。

我的阅读是这样的,没有给出错误或警告:

if ([currentContact existCust] == @"2") {
self.existCustSelection.selectedSegmentIndex = 2;
}

希望有一个很好的解决方案吗? :)

提前致谢,米奇

最佳答案

existCust 必须是字符串吗?如果它只存储数字,请考虑使用 NSNumber:

NSNumber* custNumber = [NSNumber numberWithInteger:existCustSelection.selectedSegmentIndex];

如果您确实需要字符串,请按以下步骤使用 stringWithFormat 将索引转换为字符串:

NSString* custString = [NSString stringWithFormat:@"%d", existCustSelection.selectedSegmentIndex];

stringWithFormat 的调用存在两个问题:

  1. stringWithFormatNSString 的类方法。您要求 UISegmentedControl 实例返回一个字符串,但它不知道如何执行此操作。
  2. 在 stringWithFormat 中请求 %d 后,第一个参数必须是整数,例如 2,而不是字符串 @"2".

关于ios - 我想将 UISegmentedControl.selectedSegmentIndex 保存在核心数据中 - 但如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10044942/

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