0
// 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(minutes seconds) 语句从不运行。

那么,你能看出有什么不对吗?

4

1 回答 1

3

row < 0在您的代码中,仅当minutesseconds设置为row. 但是在您的示例中,row是肯定的,因此minutesandseconds仍然是两者0,并且前三个 if 永远不会为真。

而且我对Objective-C了解不多,但是您正在使用%f打印一个整数,这可能会让您胡说八道。

于 2010-02-10T07:52:18.593 回答