【发布时间】:2012-07-25 02:53:37
【问题描述】:
我在 UIToolBar 叠加层上叠加了一个完成按钮。完成按钮出现在我的工具栏上,但不可点击。事实上,当我触摸它时,它没有任何变化。显然 doneButton 没有接收到动作。我的问题是为什么以及如何纠正这个问题?我应该用什么替换我的错误代码?
这是我设置叠加层的地方。
- (UIView*)CommomOverlay {
//Main overlay(not pertinent in this question)
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,420)];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,420)];
[FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]];
//Toolbar overlay
UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 50)];
[myToolBar setBarStyle:UIBarStyleBlack];
//Done button overlay
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneButtonPressed)];
[myToolBar setItems:[NSArray arrayWithObjects: doneButton, nil] animated:YES];
[FrameImg addSubview:myToolBar];
[view addSubview:FrameImg];
return view;
}
这是我使用的 doneButton 按下方法。单击完成后,视图应该恢复到另一个屏幕,其中 .h/.m 位于 SecondViewController 的名称中。
-(void)doneButtonPressed {
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil
bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
}
在我看来一切都是完美的,但不用说它不是。我知道这似乎是一个常见问题,但我没有搜索到关于按钮无法在叠加层上运行的问题。请不要只讨论更正部分,还要讨论为什么部分。
【问题讨论】:
-
您是否看过这个答案以进行更正以及为什么? stackoverflow.com/a/2476310/774691 我问是因为我不知道您是否尝试以允许设置toobarItems 的方式进行上述操作。