- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我更喜欢使用 UITableView 创建具有 2 级层次结构的表,如这张图片。每次用户点击标题时,内容都会折叠或展开。经过3天的研究,我发现有2个技术:
1.自定义 UITableViewCell 本身带有另一个表
2.使用节标题 View 。
现在我决定使用第二个。因为UITableView does not re-use section view (虽然 UITableView 包含 2 个私有(private)变量:_reusableHeaderViews 和 _reusableFooterViews:),但我创建了一些自定义方法来执行此任务。一切顺利,除了 1 个错误:当我使用方法 时reloadSections:withRowAnimation 与 UITableViewRowAnimationFade ,标题 View 变为空白 View 。
这是我的代码:
#import "MasterViewController.h"
@interface MasterViewController ()
//remember current section
@property (assign, nonatomic) NSInteger curSession;
@property (strong, nonatomic) NSMutableDictionary *reusableHeaderViews;
@end
@implementation MasterViewController
@synthesize reusableHeaderViews = _reusableHeaderViews;
@synthesize tableView = _tableView;
@synthesize curSession = _curSession;
@synthesize detailViewController = _detailViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Master", @"Master");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.curSession = -1;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
//method for adding header view into reuse-array
- (void)registerHeaderView:(UITableViewCell *)headerView forReuseIdentifier:(NSString *)reuseIdentifier
{
NSMutableDictionary *reusableDictionary = [self reusableHeaderViews];
if (reusableDictionary == nil)
{
reusableDictionary = [[NSMutableDictionary alloc] init]; //creates a storage dictionary if one doesn’t exist
self.reusableHeaderViews = reusableDictionary;
}
NSMutableArray *arrayForIdentifier = [[self reusableHeaderViews] objectForKey:reuseIdentifier];
if (arrayForIdentifier == nil)
{
//creates an array to store views sharing a reuse identifier if one does not exist
arrayForIdentifier = [[NSMutableArray alloc] init];
[reusableDictionary setObject:arrayForIdentifier forKey:reuseIdentifier];
}
[arrayForIdentifier addObject:headerView];
}
//get header view in reuse-array
- (UITableViewCell *)reuseableHeaderForIdentifier:(NSString *)reuseIdentifier
{
NSMutableArray *arrayOfViewsForIdentifier = [[self reusableHeaderViews] objectForKey:reuseIdentifier];
if (arrayOfViewsForIdentifier == nil)
{
return nil; //We don’t have any of this kind!
}
NSInteger indexOfAvailableHeaderView = [arrayOfViewsForIdentifier indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop)
{
//If my view doesn’t have a superview, it’s not on-screen.
return ![obj superview];
}];
if (indexOfAvailableHeaderView != NSNotFound)
{
UITableViewCell *headerView = [arrayOfViewsForIdentifier objectAtIndex:indexOfAvailableHeaderView];
return headerView; //Success!
}
return nil;
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 15;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (_curSession == section)
return section;
return 0;
}
- (UIView*) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *headerReuseIdentifier = @"Header";
UITableViewCell *cell = [self reuseableHeaderForIdentifier:headerReuseIdentifier];
if(cell == nil)
{
//Didn’t locate a reusable
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
[self registerHeaderView:cell forReuseIdentifier:headerReuseIdentifier];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openSection:)];
tapGR.numberOfTapsRequired = 1;
[cell addGestureRecognizer:tapGR];
cell.backgroundColor = [UIColor redColor];
}
cell.tag = section;
cell.textLabel.text = [NSString stringWithFormat:@"Section title %i", section];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [NSString stringWithFormat:@"Row %i - section %i", indexPath.row, indexPath.section];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void) openSection:(id)sender
{
NSInteger section = [[(UITapGestureRecognizer*)sender view] tag];
if(_curSession == -1)
{
_curSession = section;
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:_curSession] withRowAnimation:UITableViewRowAnimationFade];
}
else if(_curSession == section)
{
_curSession = -1;
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
}
else if(_curSession != section)
{
NSInteger temp = _curSession;
_curSession = -1;
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:temp] withRowAnimation:UITableViewRowAnimationFade];
_curSession = section;
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
}
}
@end
最佳答案
这有点晚了,但也许有人会有类似的问题。
你可以尝试使用这个组件:https://github.com/serverdensity/ios-SDNestedTable
关于ios - UITableView 重用section header view : header view disappear when using UITableViewRowAnimationFade,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12723871/
所以我正在尝试制作一种命运之轮游戏或刽子手。我有 33 个代表字母的按钮,1 个按钮 = 1 个字母。当用户按下其中一个时,它必须“消失”(变得禁用和不可见)。我在 SceneBuilder 中创建了
我试图让 span 元素在悬停时消失。锻炼效果不佳。 代码:(CSS) .list-item-note { font-size:9px; color:#666; font-s
使用复选框,我想更改两个单选按钮的选中状态。这工作正常,但是当再次更改复选框时,单选按钮选中视觉“消失”,而代码显示它被选中。这是怎么来的? 演示:http://jsfiddle.net/Tz99c/
每当我只是在 Eclipse 中键入一些代码,并单击灰色带状区域上的错误灯泡时,我的代码就跑掉了,我必须关闭文件并重新打开它才能看到我的代码再次编码。有人可以帮我弄清楚如何停止吗?谢谢 最佳答案 我可
我有一个相当奇怪的问题,我无法找到相关文档。我有一个使用 Delphi 内置 TDBMemo 组件的 Delphi 程序,因为该组件需要从数据库中的字段中提取数据。用户还必须能够编辑此信息,即将信息添
我正在尝试使脚本基于输入文件返回AD用户ID,显示名称和组成员身份,并将结果导出到另一个文件。 但是,组成员身份信息似乎在此过程中丢失了。 有任何想法吗? 我当前的脚本: $Result = @()
我有一个背景 Pane ,用于绘制与 BorderPane、VBox 和 HBox 结合使用时不显示的对象。此外,我的 BorderPane 没有正确定位布局(左、下、右)。我尝试过使用多个不同的 P
我在使用自定义 ArrayAdapter 的 ListActivity 中使用我的 ListView 时遇到问题。 当 ListActivity 隐藏(暂停,无论怎样)时,ArrayAdpater 中
看看这张图片 左上角是 Android 汉堡包菜单,但它是白色的。另外,右边是一个搜索放大镜,也是白色的。问题是背景是根据呈现的内容从服务器动态加载的。 是否可以对菜单图标进行着色或提升它们,以便在出
我有一个有点愚蠢的问题。问题是我的程序必须具有从数据库中删除数据的功能。是的,这不是真正的问题。但是我怎样才能删除数据而不会有其他人看到某些内容已被删除的危险。 User Table: U_ID U
我正在编写一个原型(prototype),但遇到了 GUI 问题。我希望 JPanel pCustomer 居中,但这样做它会完全消失。例如,如果我把它放在南方,一切都很好。 import javax
我正在尝试重新创建一个类似于 App Store 故事页脚中使用的 UIVisualEffectView。虽然它看起来很简单,但我无法配置模糊以在白色背景下以相同方式响应。 开箱即用,带有 .ligh
我正在尝试使用 Python 和 SQLite 更新我的用户详细信息。 目的是一次升级我的用户的所有列。 我的代码是: def update(): new_username = input("In
我的工作与网络前端开发人员/websedigner 一样独立,而且我在 Android 手机上使用 HTML5 横幅广告。在 iOS 手机和平板电脑、Chrome 或 Safari 上,它运行完美。但
我以编程方式为我的 View 设置背景图像: UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage im
假设我有一个这样定义的调试函数: namespace debug { void report(std::string message); } 我能否使用一些编译器技巧,在编译时将每个调用安全地
我在幻灯片中使用响应式断点。在小屏幕上,我一次显示一张幻灯片。在大 2 上(大意味着小于 990 像素) 示例:我将断点设置为在小屏幕上一次显示一张幻灯片,并在大屏幕上禁用 slider 。我有 8
我正在尝试用 Java 实现一个基本的物理引擎,并且使用 JOGL 绑定(bind),以便可以可视化结果。我可以轻松地创建和旋转形状,但在操作视口(viewport)和移动形状时遇到了问题。 我不认为
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有以下问题:我试图显示一个箭头,如果我从#colorSelect 中删除 overflow:hidden ,它就会起作用。但我需要 overflow:hidden 因为我里面有流元素。 我该如何解决
我是一名优秀的程序员,十分优秀!