Domanda

I assign a UIPickerView in my cellForRowAtIndexPath. This is because I assign it view a tag. It works when the view first loads, however, when I present a modal view controller, then dismiss it and return to the view containing the table with the UIPickerView, the picker is empty (has no values). I tried [tableView reloadData in ViewWillAppear thinking it would reassign the picker with its values in CellForRowAtIndexPath but it doesnt. I assign the picker object with the following code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell * cell = nil;

    [cell = createPickerCell];

    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView.backgroundColor = [UIColor clearColor];

    return cell;

}

-(UITableViewCell *) createPickerCell{
    UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:kPickerCell];
    self.picker.delegate=self;
    self.picker.dataSource =self;
    self.picker = (UIPickerView *)[cell viewWithTag:223];
    NSLog(@"picker tag is %ld",(long)self.picker.tag);
    [cell addSubview:self.stylistPicker];

    return cell;
}

If anything is unclear then please ask.

È stato utile?

Soluzione

I resolved this problem, it was very very simple. Instead of assigning it via a tag in the cell, it was much easier to just create the picker view in the cell.

-(UITableViewCell *) createPickerCell{
    UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:kPickerCell];
    self.picker = [UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 163)];// new line
    self.picker.delegate=self;
    self.picker.dataSource =self;
    [cell addSubview:self.stylistPicker];

    return cell;

}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top