你能看到这段代码有什么问题吗?因为我不能,但它仍然不起作用

时间:2010-02-10 07:44:47

标签: objective-c crash uipickerview

// When row is selected
- (void)pickerView:(UIPickerView *)pickerTimer didSelectRow:(NSInteger)row inComponent:(NSInteger)component {   
    int minutes;
    int seconds;

    if (component == 0) {
        if (row < 0){
            minutes = row;
        } else {
            minutes = 0;
        }
    }
    if (component == 1) {
        if (row < 0){
            seconds = row;
        } else {
            seconds = 0;
        }
    }
    NSLog([NSString stringWithFormat:@"%f %f %d", minutes, seconds, row]);
    if (minutes != 0 && seconds != 0){
        [buttonTimer setTitle:[NSString stringWithFormat:@"%@ minutes and %@ seconds", minutes, seconds] forState:UIControlStateNormal];
    // Yes, I am trying to set the label of a button.
    }
    if (minutes == 0 && seconds != 0){
        [buttonTimer setTitle:[NSString stringWithFormat:@"%@ seconds", seconds] forState:UIControlStateNormal];
    }
    if (minutes != 0 && seconds == 0){
        [buttonTimer setTitle:[NSString stringWithFormat:@"%@ minutes", minutes] forState:UIControlStateNormal];    
    }
    if (minutes == 0 && seconds == 0){
        [buttonTimerFarts setTitle:[NSString stringWithFormat:@"Set time before play starts..."] forState:UIControlStateNormal];
    }

}

控制台将显示诸如

之类的内容

0.000000 -1.993950 2751746

三个第一个if(分钟秒)语句,从不运行。

那么,你能看到什么问题吗?

1 个答案:

答案 0 :(得分:3)

在您的代码中,仅当row < 0minutesseconds设置为row时。但在您的示例中,row为正,因此minutesseconds仍为0,前三个ifs永远不会为真。

我对Objective-C了解不多,但你打印的是一个%f的整数,这可能会让你胡说八道。