[英]ios Custom multiple selection for tableview
我有一张桌子,里面有三个部分。 每节有4行。 我希望每个部分有一个选择,这使得整个表有3个选择。 我正在尝试使用以下功能进行此操作,这些功能可重置当前部分并设置新选择。
- (void)selectOneRow:(int)row inSection:(int)section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
for(int i = 0; i < [[self.dataSource objectAtIndex:section] count]; ++i) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:section];
[self.table deselectRowAtIndexPath:ip animated:NO];
//[[self.table cellForRowAtIndexPath:ip] setHighlighted:NO];
}
[self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
//[[self.table cellForRowAtIndexPath:indexPath] setHighlighted:YES];
[self disableInteractionForRow:row inSection:section];
}
- (void)disableInteractionForRow:(int)row inSection:(int)section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
for(int i = 0; i < [[self.dataSource objectAtIndex:section] count]; ++i) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:section];
[[self.table cellForRowAtIndexPath:ip] setUserInteractionEnabled:YES];
}
[[self.table cellForRowAtIndexPath:indexPath] setUserInteractionEnabled:NO];
}
选择第一部分的第一行的示例是:
[self selectOneRow:0 inSection:0];
这在第一次时效果很好,但是每次添加后记后,它都会关闭该行,使该部分为空白。 我怎样才能解决这个问题? 还是我首先要解决所有这些错误? 感谢您的帮助。
**编辑添加图像**
听起来您正在尝试使其变得过于复杂。 而不是将三个选项放在一个包含三个部分的表格视图中,而是制作三个单独的表格和三个单独的视图。
例如,转到iPhone上的设置应用。 点击“邮件,联系人,日历”,然后向下滚动到“邮件”部分标题下的“显示”,“预览”和“最小字体大小”选项。 对于这些设置中的每一个,将使用新的表视图控制器推送新视图,并且您只能选择其中一个选项,然后返回。 这样可以保持界面整洁,更不用说您的代码了。
希望像这样进行重组将对您更好。 我不知道我是否可以说您现在的做法是错误的,但这与Apple构建其应用程序的方式不一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.