开发者

Can you see anything wrong in this code? 'Cause I can’t, but it still doesn’t work

开发者 https://www.devze.com 2022-12-19 14:05 出处:网络
// When row is selected开发者_JS百科 - (void)pickerView:(UIPickerView *)pickerTimer didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// When row is selected开发者_JS百科
- (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];
    }

}

The console will display things such as

0.000000 -1.993950 2751746

The three first if(minutes seconds) statements, never runs.

So, can you see anything wrong?


In your code, only if row < 0, minutes or seconds is set to row. But in your example, row is positive, so minutes and seconds are still both 0, and the first three ifs are never true.

And I don't know much about Objective-C, but you're printing an integer with %f, and that might give you nonsense.

0

精彩评论

暂无评论...
验证码 换一张
取 消