- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义 TabbarViewController
这基本上隐藏了标准选项卡 View 。我附加了一个按钮,当按下该按钮时,会在屏幕上显示一个菜单。长时间使用该应用程序时一切正常,但在某些时候它会崩溃并出现 EXC_BAD_ACCESS
或 SIGABRT
.
奇怪的是当我添加了 NSLog
打印 tabbarController
和 menuView
在检查 menuView 是否是 tabbarController
的 subview 之前,它在 NSLog
上崩溃了行(在我看来,其中一个已被释放,但没有明确调用,它们都被保留)。
这种崩溃从未在模拟器上发生过。关于有什么问题的任何想法?
AppDelegate.h
UIButton *ribbon;
RibbonMenu* menu;
@property (nonatomic, retain) CustomTabbarController* tabbarController;
@property (nonatomic, retain) UIView* menuView;
@synthesize tabbarController;
@synthesize menuView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
tabbarController = [[CustomTabbarController alloc] init];
[tabbarController setTabBarHidden:YES animated:NO];
tabbarController.viewControllers = [NSArray arrayWithObjects: EventsNavigation, StyleNavigation, BrandNavigation, MemberNavigation, settingsNavigation, nil];
ribbon = [UIButton buttonWithType:UIButtonTypeCustom];
[ribbon retain];
UIImage* img = [UIImage imageNamed:@"toppart.png"];
[ribbon setImage:img forState:UIControlStateNormal];
ribbon.frame = CGRectMake(234,0,86,97);
//MENU SELECTOR
[ribbon addTarget:self action:@selector(didClickMenu) forControlEvents:UIControlEventTouchUpInside];
[tabbarController.view addSubview:ribbon];
self.window.rootViewController = tabbarController;
[self.window makeKeyAndVisible];
}
- (void) didClickMenu {
if (!menuView) {
menu = [[RibbonMenu alloc] init];
menuView = menu.view;
menuView.backgroundColor = [UIColor clearColor];
[blinkTimer invalidate];
ribbon.selected = NO;
}
if ([tabbarController.view.subviews containsObject:menuView]) {
[self removeMenu];
} else {
menuView.frame = CGRectMake(235,-370,82,432);
//**CRASH HERE**
[tabbarController.view insertSubview:menuView belowSubview:ribbon];
[UIView transitionWithView:menuView
duration:0.2
options:UIViewAnimationOptionCurveLinear
animations:^ { menuView.frame = CGRectMake(235,0,82,432);}
completion:nil];
}
}
-(void) removeMenu {
[UIView transitionWithView:menuView
duration:0.2
options:UIViewAnimationOptionCurveLinear
animations:^ { menuView.frame = CGRectMake(235,-370,82,432);}
completion:^(BOOL finished) {[menuView removeFromSuperview];}];
}
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x35a5388f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x33677259 objc_exception_throw + 33
2 CoreFoundation 0x35a53789 +[NSException raise:format:] + 1
3 CoreFoundation 0x35a537ab +[NSException raise:format:] + 35
4 UIKit 0x33313cf1 __windowForView + 157
5 UIKit 0x33155ccd -[UIView(Hierarchy) _postMovedFromSuperview:] + 21
6 UIKit 0x3315680d -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1169
7 UIKit 0x33172071 -[UIView(Hierarchy) insertSubview:belowSubview:] + 29
8 MyAppName 0x000c6af3 -[AppDelegate didClickMenu] (AppDelegate.m:247)
最佳答案
这种崩溃也应该发生在模拟器上。在 didClickMenu
您尝试访问 menuView。但是,从外观上看,您没有名为 menuView 的实例变量。您有一个 房产 调用 menuView,但您需要使用 self.menuView
调用此属性.
或者,如果您使用的是 Xcode 4.4 或更高版本并且您没有合成您的属性,编译器将为您创建一个实例变量。此实例变量与属性同名,但带有 _ 前缀——在本例中为 _menuView
.
关于iphone - iOS insertSubview :belowSubview: crashing with SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14313507/
我知道 insertSubView 会在 iPhone 应用程序 View 层次结构的某个索引处插入一个新 View 。 我也明白 insertSubView atIndex:[[self.view
在我的容器 Controller 中,用户可以平移 View 以切换到不同的 View 。当平移手势开始时,它会将新 View Controller 的 View 添加到 View 中:view.in
向 UIView 添加 subview 时,方法 addView: 和 insertView:atIndex: 有什么区别? 最佳答案 两者都将 View 作为 subview 添加到接收器,这会导致
我有一个自定义 TabbarViewController这基本上隐藏了标准选项卡 View 。我附加了一个按钮,当按下该按钮时,会在屏幕上显示一个菜单。长时间使用该应用程序时一切正常,但在某些时候它会
我正在使用 Storyboards 开发一个运行 iOS 5.1 的 iPhone 应用程序。我有一个 UIViewController,底部有一个 UITabBar 组件。我正在使用 UITabBa
有点问题,这里是分割: 我的 AppDelegate 使用 rootViewController 作为 View Controller 。这个 View Controller 的目的是交换几个其他 V
我检查了很多这种方法的例子,但仍然无法弄清楚我在做什么有什么问题。我正在尝试在当前 View 下方添加另一个 View ,然后在用户单击当前屏幕上的按钮后删除我的当前 View 。由于某种原因, Vi
我一直在尝试使用 insertSubview:atIndex:在另一个下插入 subview 。问题是大多数时候不是上面索引较高的 View ,而是最后添加的 View 。我注意到,如果我选择索引 0
sendSubviewToBack 和 insertSubview:belowSubview: 方法有问题。简单地说,我有一个按钮,我将其插入到另一个 View _centerView 下方。我希望按
我有一个 UIView,在本例中有 4 个 subview 。我希望能够更改 subview 的顺序,但我似乎无法使用 [UIView insertSubview: atIndex:] 在一个特定的
在我的 Storyboard 上,我添加了一个点击图标作为 UIImageView,在代码中,我通过创建圆形 View 并放大和淡化它们来使其脉动并添加“波纹”效果。我使用 insertSubview
我有零错误。唯一的问题是我的模拟器中没有任何显示。我猜这是因为我在 awakeWithContext 中没有任何东西?我确实有 self.view.insertSubview(heartSymbol,
我以编程方式向特定 View 添加了 4 个 subview (label1、label2、label3、label4)和约束(label2 顶部取决于 label1 底部等)。现在我使用 inser
我是一名优秀的程序员,十分优秀!