【发布时间】:2015-05-27 09:11:21
【问题描述】:
我已将第三方库导入到我的项目中,我将其称为原始项目的 appDelegate 中的主 ViewController。我正在尝试添加一个后退按钮(不更改第三方库的代码)。
我在我的 AppDelegate 中向 VC 展示以下内容
ABSViewController *abs = [[ABViewController alloc] init];
[self.window.rootViewController presentViewController:abs
animated:NO
completion:nil];
然后我尝试使用下面的程序以编程方式添加我的 UIButton,但即使调用“bringSubViewToFront”它也不会出现在前面
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
backButton.layer.backgroundColor = [UIColor blueColor].CGColor;
[abs.view addSubview:backButton];
[abs.view bringSubviewToFront:backButton];
我可以看到按钮是在 presentViewController 动画完成之前创建的,但它设置在 ABSViewController(库 ViewController)后面
【问题讨论】:
-
调用
presentViewController后在哪里添加按钮?? -
这个视图是如何呈现的?如果您使用导航控制器并按下此 VC,则可以设置
navigationItem.backBarButtonItem = [UIBarButton alloc] init ...],您将获得此返回按钮。 -
如果是 VC,你也可以设置
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelPicker)];
标签: ios objective-c xcode xcode6