如何通过点击barbuttonitem获取新视图?

时间:2012-07-31 05:31:36

标签: ios uibarbuttonitem

我在工具栏叠加层上以编程方式创建了一个barbuttonitem。访问我的相机时会出现所有这些。按钮功能正常,选择器完全可以调用它。

这是.m中的叠加层,看看doneButton选择器。

- (UIView*)CommomOverlay  {
//Both of the 428 values stretch the overlay bottom to top for overlay function. It
doesn't cover it. 
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"]];
FrameImg.userInteractionEnabled = YES;




UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 50)];


UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(doneButtonPressed)];

[myToolBar setItems:[NSArray arrayWithObjects: cancelButton, flexiSpace2, flexiSpace,
doneButton, nil] animated:YES];

[view addSubview:FrameImg];
[view addSubview:myToolBar];
return view;



}

这是我用于我的虚函数的方法。

//NewViewController is the nib I want to bring up when done is clicked.
-(void)doneButtonPressed {

NewViewController *UIView = [[NewViewController alloc] initWithNibName:nil bundle:nil];
UIView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:UIView animated:NO];
[UIView release];
NSLog(@"Acknowledged!");
}

正在调用按钮,但没有任何反应。正如您所看到的,我添加了一个NSLog函数来查看它是否被调用。单击按钮时,“已确认”会显示在日志中,因此选择器不会出现问题。当我使用按钮时,应用程序不会崩溃,如果我做了一些严重错误的编码(实际上我甚至没有得到任何关于它的警告)应该发生,就Xcode而言,一切都很好,不用说不是。

我还在正在实现此代码的视图控制器中正确放置了NewViewController的.h文件。

1 个答案:

答案 0 :(得分:0)

UIView是一个类的名称。不要将它用作变量的名称。充其量是非常令人困惑的,并且可能是您遇到问题的原因。在UIView中将myView重命名为doneButtonPressed