Search code examples
iosobjective-cuipickerview

UIPickerView Scrolling Can cause crash with no error?


Im using a picker view which seems to work but on occasion triggers a stack trace crash with no error for me to work with.

Here is my picker view setup, it works just fine, however at total random, it can crash the app.

Any ideas as to what could be the cause?

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
                return 1;
            }

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
                return _pickerChannels.count;
            }

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
                UILabel *labelSelected = (UILabel*)[_channelPickerView viewForRow:row forComponent:component];
                [labelSelected setTextColor:[UIColor whiteColor]];
                self.channelGroupValue = [_pickerChannels indexOfObject:_pickerChannels[row]];
                [[self delegate] sideBarDidScrollChannels:self.channelGroupValue];
                [[self delegate] sideBarDidSetScrollChannels:self.channelGroupValue];
            }

- (UIView *) pickerView: (UIPickerView *) pickerView viewForRow: (NSInteger) row forComponent: (NSInteger) component reusingView:(UIView *)view {
        UILabel *label = (id)view;
        if (!label)
        {
            label= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [_channelPickerView rowSizeForComponent:component].width,
                                                                         [_channelPickerView rowSizeForComponent:component].height)];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor whiteColor];
            [label setFont:[UIFont systemFontOfSize:17]];
            label.text = _pickerChannels[row];
        }
        return label;
    }

This is the only info i can provide on the crashing:

enter image description here


Solution

  • I guess the crash is about CDCControl setTCPWrite which occasionally occurs because you are using multithread, as you can see on your stack.
    To be more specified, maybe there are two threads calling CDCControl setTCPWrite at the same time.