【发布时间】:2016-07-06 10:02:41
【问题描述】:
我有一个包含 5 个部分的表格视图,并且我已将表格视图选择设置为多个。每个部分都有不同的行数。我想要设置用户只能从每个部分中选择一个单元格(在我的表格中,用户可以选择任意数量的单元格)。 例如:5 个部分的 5 个单元格。
应该不可能从任何部分选择多个单元格。如果用户从同一部分选择另一个单元格,则应取消选择先前选择的单元格。我怎样才能做到这一点。这是 didSelectRowAtIndexPath 的示例实现。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
HoteldetalcelloneTableViewCell *cellone = (HoteldetalcelloneTableViewCell *)[self.detailtableView cellForRowAtIndexPath:indexPath];
HoteldetailcelltwoTableViewCell *celltwo = (HoteldetailcelltwoTableViewCell *)[self.detailtableView cellForRowAtIndexPath:indexPath];
//I have implement for two sections to test.
if(indexPath.section == 0)
{
HotelDetailsone *secone = [roomonearray objectAtIndex:indexPath.row];
HoteldetailsforBooking *book = [HoteldetailsforBooking new];
if([secone.offerallow isEqualToString:@"True"])
{
celltwo.selectedsignLabel.hidden = NO;
}
else
{
cellone.selectedsignLabelone.hidden = NO;
}
// [self.detailtableView reloadData];
NSLog(@"price for room 1 : %@", secone.itempriceText);
}
else
{
HotelDetailsone *sectwo = [roomtwoarray objectAtIndex:indexPath.row];
HoteldetailsforBooking *book = [HoteldetailsforBooking new];
if([sectwo.offerallow isEqualToString:@"True"])
{
celltwo.selectedsignLabel.hidden = NO;
}
else
{
cellone.selectedsignLabelone.hidden = NO;
}
// [self.detailtableView reloadData];
NSLog(@"price for room 1 : %@", sectwo.itempriceText);
}
}
【问题讨论】:
-
您是希望只允许从整个表格中选择一项,还是每节选择一项?
-
每个部分选择一个@Lion
-
你这里有多少个自定义单元格?
-
你有 5 个部分。所以我认为一个自定义单元格对你来说就足够了。
-
我建议让 tableview 多选并根据选择的部分进行验证。 (即不允许在同一部分中进行其他选择)
标签: ios objective-c uitableview didselectrowatindexpath sections