【发布时间】:2014-11-25 12:38:07
【问题描述】:
我正在尝试使用滑动手势来切换视图。我的滑动正在工作并正在处理,但不知何故,视图开关无法正常工作。
滑动手柄的代码如下:
-(void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer{
CGPoint location = [gestureRecognizer locationInView:tableView];
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:location];
if(indexPath){
userCell *cell = [tableView cellForRowAtIndexPath:indexPath]; //userCell inherits from UITableViewCell so why complain?
StatisticsViewController *statisticsView = [StatisticsViewController new];
[self.view removeFromSuperview];
[self.view addSubview:statisticsView.view];
//[self.view insertSubview:statisticsView.view atIndex:0];
}
} `
我之前使用过 insertSubview: atIndex:0,因为我已经注释掉了。 我的问题是我试图添加的新视图没有被添加。 removeFromSuperview 在我得到黑屏的意义上起作用(因此删除了视图)。但我不明白为什么我不能添加另一个视图(我创建一个实例的 statisticsView;我正在使用情节提要并有一个带有一些标签和颜色的 StatisticsViewController 只是为了测试),删除后我只是得到一个黑屏看法。 顺便说一句,我正在使用名为 FrontPageViewController 的 rootviewcontroller 工作。 我不知道是否有一个干净的视图控制器(根)加载到 frontpageviewcontroller 中,然后在我需要加载另一个视图时将其切换出来是否更“正确”。 (但我不明白为什么我目前的方法行不通)。 提前致谢
【问题讨论】:
-
我不确定你是否在点燃我之前阅读了我的整个帖子。你有没有读过我写的关于我的方法的内容?可能不会?代码是否错误,您的代码可能只是描述了我对这种方法的询问,不确定..因为您的解释有点..bad
-
编辑:猜想你在进一步阅读后删除了你的下一条评论。我也会
-
我试图从超级视图中删除我的 current 视图的唯一原因是因为 [self.view addSubview:statisticsView.view];或 //[self.view insertSubview:statisticsView.view atIndex:0];正在努力显示我希望用户看到的视图。加上我首先尝试 [super.view addSubview ...........] 然后沮丧地尝试 self.view 我猜^^
-
use this at 将被调用一次 if([recognizer state] == UIGestureRecognizerStateBegan)
-
zaheer,我不明白。你的话也有点绕。你能详细说明一下吗?但是我的手势没有问题(我只是用手势来做切换)
标签: ios objective-c view