【问题标题】:Multiplication of Integers in Textfield - Xcode 4.4文本字段中的整数乘法 - Xcode 4.4
【发布时间】:2012-08-10 06:06:53
【问题描述】:

我正在尝试将三个不同文本字段中的整数值相乘。

@property (nonatomic,strong) IBOutlet UITextField *textField;
@property (nonatomic,strong) IBOutlet UITextField *textField2;
@property (nonatomic,strong) IBOutlet UITextField *textField3;
@property (nonatomic,strong) IBOutlet UILabel *total;

我正在尝试在 UILabel 中显示产品。有人可以帮助实施吗?非常感谢!

【问题讨论】:

    标签: objective-c ios xcode4 xcode4.2 xcode4.3


    【解决方案1】:

    要在 UILabel 中显示产品,请以这种方式设置标签文本(假设 textFields 都包含整数):

    total.text = [NSString stringWithFormat: @"%i", (textField.text.intValue * textField2.text.intValue * textField3.text.intValue)];
    

    你可能想把它放在一个单独的方法中,这样你就可以从任何地方调用它,比如每当用户用新数字更新 textFields 时

    【讨论】:

    • 应使用floats 而不是ints 作为输入值,否则答案可能包含小数。
    • post 明确表示他们希望将整数值相乘。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多