iphone - 无法比较我的 UIPickerView 中的值

标签 iphone ios objective-c xcode

我正在尝试根据 UIPickerView 中的第一个和第二个选择输出特定数字。我这里有这段代码。

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if([[list objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"1 Gallon"] && [list2 objectAtIndex:[pickerView selectedRowInComponent:1] isEqual: @"Grams"])
        output.text = @"1 GALLON GRAMS";
    if([[list objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"2 Gallons"] && [list2 objectAtIndex:[pickerView selectedRowInComponent:1] isEqual: @"Ounces"])
        output.text = @"2 GALLONS OUNCES";
}

但我不断收到 No visible @interface for NSMutableArray declares the selector objectAtIndex:isequal

错误

我应该如何比较这两个值的返回值?像 IF comp(0) == 3 and comp(1) ==2,输出 3.4 到我的标签。

最佳答案

那是因为 NSMutableArray 没有“objectAtIndex: isEqual”选择器。

您需要从选择器 View 中获取 NSString,然后将其与您存储在 NSMutableArray 对象中的字符串进行比较(这些对象可能是名为“list”和“list2 ").

例如

NSString * stringPointedToFromPicker = (NSString *)[list objectAtIndex: [pickerView selectedRowInComponent: 0]];
if([stringPointedToFromPicker isEqual: @"1 Gallon"]) // okay for now, but do you want
    output.text = @"1 GALLON GRAMS";        // hard coded, non-localized strings like this?

关于iphone - 无法比较我的 UIPickerView 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16006424/

相关文章:

iphone - 在 Xcode 4.3 中添加 UIViewController 子类

ios - 更改应用语言并更新版本

iphone - 重新排列 UIScrollView 中的 subview ,就像主屏幕上的应用程序图标一样

objective-c - 为什么 UIAlertView dismissAnimated : work at all?

ios - 键值观察的新手;为什么我无法在我的 AppDelegate 中监控 int 的值?

iphone - UIButton 标记未在 cellForRowAtIndexPath 中正确设置

javascript - 在 Iphone Web 应用程序上使用 canvas drawImage() 函数

iphone - 将 subview 添加到 UITableViewCell 问题

objective-c - 使用 block 和变量 iOS 的枚举

ios - UILabel 切断符号