【发布时间】:2015-08-19 21:33:29
【问题描述】:
点击 UIButton 时出现 EXC_BAD_ACCESS 错误。如果我将逻辑移动到RootViewController.m 它可以工作,但在我的PanelViewController.m 中实现时则不行。我不明白为什么这不起作用,我缺少什么以及如何使它起作用?
RootViewController.m
#import "RootViewController.h"
#import "PanelViewController.h"
@interface ListViewRootController ()
@end
@implementation ListViewRootController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[self.view setBackgroundColor:[UIColor blueColor]];
PanelViewController *panelView = [[PanelViewController alloc] init];
[self.view addSubview:panelView.view];
}
@end
PanelViewController.m
#import "PanelViewController.h"
@interface PanelViewController ()
@end
@implementation PanelViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
topBar.backgroundColor = [UIColor whiteColor];
UIButton *mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, topBar.frame.size.height)];
[mapButton setTitle:@"Map" forState:UIControlStateNormal];
[mapButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[mapButton addTarget:self action:@selector(mapViewToggle:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:topBar];
[topBar addSubview:mapButton];
}
- (void)mapViewToggle:(UIButton *)sender{
NSLog(@"hello, is it me youre looking for");
}
@end
【问题讨论】:
标签: ios objective-c uiview uibutton subview