iphone - 将 UITextField 标签转换为字符串

标签 iphone objective-c ios

这给了我一个错误,“Bad Reciever type 'NSIntegar”(又名'int')。

    NSString *tempTag = [((UITextField *)[self.dataSetDictionary objectForKey:key]).tag stringValue];

试图将 uitextfield 的标签强制转换为字符串。我可以很好地使用 [NSString stringWithFormat],只是想不通为什么这种方式行不通。

最佳答案

你必须使用stringWithFormat:

UITextField *textField = (UITextField *)[self.dataSetDictionary objectForKey:key];
NSString *tempTag = [NSString stringWithFormat:@"%d", textField.tag];

just can't figure out why this way won't work.

因为 tag 是标量整数而不是对象。您不能向非对象发送像 stringValue 这样的消息。

关于iphone - 将 UITextField 标签转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8792053/

相关文章:

objective-c - 如何制作一个出现在全屏窗口顶部的 Cocoa 窗口?

ios - 分发 iOS 应用程序时出错 ITMS-9000

iphone - 将 3 个 UItextfield 中的数据分配到 3 个不同的字符串中

iphone - 相机代码在iPad2上崩溃

iphone - 在 View 之间划线的最佳方法是什么?

ios - Wikitude/AR SDK 用于在 3d 空间中挑选对象

objective-c - SKAction scale physics body

ios - 如何将 View 添加为 UITableViewCell 的 subview 但位于所有其他 View 之上

ios - 改变限制

iphone - 使用 CMMotionManager iPhone 的生涩 Action