【发布时间】:2016-02-22 16:06:04
【问题描述】:
我遇到的问题是我想通过单击 UIView(页脚)内的按钮来调用 navigationController 中的方法。当我按下按钮时,它应该调用我试图访问的方法以在下面的代码中打开录像机。
有人告诉我我可以实现委托方法或使用 NSNotification。以下是我所拥有的:
我的页脚 (ESPhotoDetailsFooterView.m) 有我创建的按钮。我的页脚只包含一个 UIView。
我试图在页脚中访问的方法位于 (ESTabBarController.m)
这是我按下按钮时试图触发的:
RecorderViewController *viewController = [[RecorderViewController alloc] init];
[viewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self.navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self.navController pushViewController:viewController animated:NO];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:self.navController animated:YES completion:nil];
});
我是 Objective C 的新手并且了解基础知识。我无法弄清楚我需要做什么来完成这个。任何帮助将不胜感激。
按钮的代码如下:
// Create a standard UIButton programmatically using convenience method
UIButton *camButton = [UIButton buttonWithType:UIButtonTypeCustom];
// Set the location (x,y) and size (width,height) of the button
camButton.frame = CGRectMake(9.0f, 8.0f, 35.0f, 35.0f);
// Create UIImages from image resources in your application bundle
// using convenience methods (no need to release)
UIImage *normal = [UIImage imageNamed:@"BingComm"];
UIImage *highlighted = [UIImage imageNamed:@"BingCommClick"];
// Set the button's background to an image
[camButton setBackgroundImage:normal forState:UIControlStateNormal];
[camButton setBackgroundImage:highlighted forState:UIControlStateHighlighted];
// Add the target-action for the touch event
#pragma GCC diagnostic ignored "-Wundeclared-selector"
[camButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.mainView addSubview:camButton];
【问题讨论】:
-
如何在故事板或代码中设置按钮?目前尚不清楚按钮的目标,即按下按钮时被告知的对象(理想情况下是某种类型的视图控制器)是否根据您上面描述的内容正确设置。如果您提供更多细节,我可能会让您朝着正确的方向开始
-
我在上面添加了我正在使用的按钮代码。
标签: ios objective-c iphone uiview