2015-06-01 3 views
-1

Как добавить UIPickerView внутри UITableViewCell?Добавить UIPickerView внутри UITableview

Есть ли что-нибудь новое с InlinePicker или просто попробуйте добавить в подзаголовок в ячейку?

Пожалуйста, ответьте на мой вопрос & удалить мое замешательство/сомнение относительно inLinePicker

+1

возможно дубликат [IOS 7 - Как отобразить окно выбора даты на месте в виде таблицы] (http://stackoverflow.com/questions/18973573/ios-7- как к дисплею-а-дата-подборщик на месте-в-табличного-зрения) –

ответ

1

Apple, дал пример код для DateCell

Вот некоторые фрагменты код из него:

- (BOOL)hasPickerForIndexPath:(NSIndexPath *)indexPath 
{ 
    BOOL hasDatePicker = NO; 
    NSInteger targetedRow = indexPath.row; 
    targetedRow++; 
    UITableViewCell *checkDatePickerCell = 
     [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:targetedRow inSection:0]]; 
    UIDatePicker *checkDatePicker = (UIDatePicker *)[checkDatePickerCell viewWithTag:kDatePickerTag]; 
    hasDatePicker = (checkDatePicker != nil); 
    return hasDatePicker; 
} 

- (void)updateDatePicker 
{ 
    if (self.datePickerIndexPath != nil) 
    { 
     UITableViewCell *associatedDatePickerCell = [self.tableView cellForRowAtIndexPath:self.datePickerIndexPath]; 
     UIDatePicker *targetedDatePicker = (UIDatePicker *)[associatedDatePickerCell viewWithTag:kDatePickerTag]; 
     if (targetedDatePicker != nil) 
     { 
      NSDictionary *itemData = self.dataArray[self.datePickerIndexPath.row - 1]; 

      [targetedDatePicker setDate:[itemData valueForKey:kDateKey] animated:NO]; 

     } 

    } 

} 
- (BOOL)hasInlineDatePicker 

{ 
    return (self.datePickerIndexPath != nil); 
} 

- (BOOL)indexPathHasPicker:(NSIndexPath *)indexPath 

{ 
    return ([self hasInlineDatePicker] && self.datePickerIndexPath.row == indexPath.row); 

} 

- (BOOL)indexPathHasDate:(NSIndexPath *)indexPath 

{ 
    BOOL hasDate = NO; 
    if ((indexPath.row == kDateStartRow) || 

     (indexPath.row == kDateEndRow || ([self hasInlineDatePicker] && (indexPath.row == kDateEndRow + 1)))) 

    { 
     hasDate = YES; 

    } 
    return hasDate; 
} 
0

С This link

Вы будете должны выделить UIPickerView в cellForRowAtIndexPath

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

if(indexPath.row == pickerRow){ 
UIPickerView *pickerView = [[UIPickerView alloc]init]; 
cell = ... // alloc and initialize a cell 
cell addSubview:pickerView]; 
} 
else{ // your other cells } 

return cell; 
}