我有一个包含三个部分的表。每个部分有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];
第一次使用效果很好,但每次使用后都会关闭行,将该部分留空。我怎样才能解决这个问题?或者我首先要解决这个问题?谢谢你的帮助。
**编辑添加图片**
答案 0 :(得分:1)
听起来你正试图让它变得太复杂。不是在一个包含三个部分的表视图中放置三个选项,而是创建三个单独的表和三个单独的视图。
例如,转到iPhone上的设置应用。点击“邮件,通讯录,日历”,然后向下滚动到“邮件”部分标题下的“显示”,“预览”和“最小字体大小”选项。对于这些设置中的每一个,使用新的表视图控制器推送新视图,您只能选择其中一个选项然后返回。这样可以保持界面清洁,更不用说代码了。
希望像这样重组它会更好地为您服务。我不知道我是否可以说你现在这样做的方式是错误的,但这与Apple如何构建他们的应用程序不一致。