Я работаю над реализацией UITableView с тремя разделами. Последняя строка второго раздела должна отображать экземпляр UIPicker.UITableView ячейка, отображающая неправильное содержимое после изменения высоты
Как таковой, я изменил высоту для этой конкретной строки, как показано ниже:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat rowHeight = self.tableView.rowHeight;
if (indexPath.section == RedZoneSection && indexPath.row == MonitorConfigRow){
rowHeight = 162;
return rowHeight;
}
return rowHeight;
}
Однако, когда я добавить, что код, первая строка («Только оповещения Из») в третьем раздел добавления к нему UISwitch это мнение, которое не должно быть, как показано ниже:
ниже, где я осуществить cellForRowAtIndexPath
для третьей секции:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForTimeOfDayRestrictionsRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SettingsRowCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.backgroundColor = [UIColor colorWithRed:0.922 green:0.937 blue:0.949 alpha:1];
switch (indexPath.row) {
case HourTimeZoneRow:
cell.textLabel.text = NSLocalizedString(@"Only Alert From", @"Only Alert Row");
break;
default:
break;
}
return cell;
}
EDIT Конкретный UISwitch, который отображается снова в неправильном месте, первоначально находится во второй ячейке в первом разделе моей таблицы. Ниже приводится реализация cellForRowAtIndexPath
для этого раздела:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubscribedNotificationsRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SettingsRowCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.backgroundColor = [UIColor colorWithRed:0.922 green:0.937 blue:0.949 alpha:1];
UISwitch *cellSwitch = nil;
switch (indexPath.row) {
case RowOne:
cell.textLabel.text = NSLocalizedString(@"Row One", @"Row One");
cellSwitch = [[UISwitch alloc] init];
cell.accessoryView = cellSwitch;
break;
case RowTwo:
cell.textLabel.text = NSLocalizedString(@"Row Two", @"Row Two");
cell.accessoryView = cellSwitch;
break;
// cell.textLabel.text = nil ;
cell.accessoryView = UITableViewCellAccessoryNone;
accessoryViewIsShowing = FALSE;
break;
}
if (cell.accessoryView == nil) {
NSLog(@"Cell accessoryView is nil");
}
else if (cell.accessoryView != nil){
NSLog(@"Cell accessoryView is not nil");
}
NSLog(@"Section: %ld, Row: %ld", (long)indexPath.section, (long)indexPath.row);
return cell;
}
Кто-нибудь знает, почему изменения высоты конкретной ячейки с причиной неправильного содержания, которое будет отображаться в ячейке в другом разделе?
Я не могу найти ту часть, где вы добавляете 'UISwitch' программно в ячейки таблицы. Есть ли дополнительный код в вашей 'cellForTimeOfDayRestrictionsRowAtIndexPath:', который вы не показывали, чтобы сократить пример? – dasblinkenlight
HI @dasblinkenlight, Да, я боялся, что вопрос слишком длинный. Я только что отредактировал его, чтобы включить туда, где «UISwitch» добавляется в ячейки в первой строке. Спасибо! – narner
Вы перерабатываете ячейку и не можете удалить переключатель из старой ячейки. –