Ios 智能UITableView标题视图
我需要具有自定义标题视图的表视图。当我触摸这个标题视图时,我会让她调整大小。我的类Ios 智能UITableView标题视图,ios,objective-c,uiview,ios8,uiviewanimation,Ios,Objective C,Uiview,Ios8,Uiviewanimation,我需要具有自定义标题视图的表视图。当我触摸这个标题视图时,我会让她调整大小。我的类topBarViewController带有下一个代码(例如): topBarViewController类: - (void)viewDidLoad { [super viewDidLoad]; self.view.frame = CGRectMake(0, 0, 320, 48); [self.view setBackgroundColor:[UIColor greenColor]]
topBarViewController
带有下一个代码(例如):
topBarViewController类:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.frame = CGRectMake(0, 0, 320, 48);
[self.view setBackgroundColor:[UIColor greenColor]];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = self.view.frame;
frame.size.height+=50;
self.view.frame = frame;
} completion:^(BOOL finished) {
}];
}
然后,我将此视图设置为表视图的标题视图。在触摸事件中,我与下一个文本发生碰撞:
2014-10-05 01:00:07.580 UGTUMap[4715:1988098] -[UITransitionView handleSingleTap:]:
unrecognized selector sent to instance 0x7ff6d542a5f0
2014-10-05 01:00:07.586 UGTUMap[4715:1988098] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UITransitionView handleSingleTap:]:
unrecognized selector sent to instance 0x7ff6d542a5f0'
找不到解决办法。有什么建议吗?您不希望top直接为headerView的大小设置动画。您希望告知UITableView通过UITableViewDelegate协议更改大小 因此,我假设您正在执行类似的操作来设置标题:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.topBarViewController.view;
}
在UITableViewDelegate中,设置一个属性以保持头部视图高度
@property (nonatomic, assign) CGFloat headerViewHeight;
执行HeightForHeaderIn部分以返回此变量
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return self.headerViewHeight;
}
当检测到headerView上的点击时,可以告诉tableView设置更新动画:
- (void)headerWasTapped {
// set new height
self.headerViewHeight = 100.0f
// animate updates
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
显示创建
topBarViewController
的代码,并将其设置为表格视图的标题视图。我的猜测是,您创建了topBarViewController
,使用了它的视图,但从未保留对视图控制器的强引用(topBarViewController
实例)。@rmaddy谢谢,强引用是一个解决方案!虽然这在很大程度上是真实的,但它并没有试图回答这个问题——这是关于一场撞车的问题。