我有一个自定义UITableViewCell
,我正在为数据源分配一些属性,例如标签。但我也在内部动态创建一个控件cellForRowAtIndexPath:
,然后将其添加到单元格中。由于我使用dequeReusableCellWithIdentifier:
的是动态内容,因此变得一团糟。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.stepperView.tag = [indexPath row];
[cell.stepperView addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[[cell.calendarView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
//THIS LINE ADDS A DYNAMIC CONTENT TO THE CELL
[self addDatePicker:cell];
return cell;
}
-(void) addDatePicker:(AutomaticAnnualIncreasesCell *)cell
{
DatePicker *datePicker = [[DatePicker alloc] initWithFrame:CGRectMake(0, 0, cell.calendarView.frame.size.width, cell.calendarView.frame.size.height)];
datePicker.tag = 100;
if([cell.calendarView viewWithTag:datePicker.tag] != nil)
{
[cell.calendarView addSubview:datePicker];
}
}