ios - View 中添加的事件按钮不起作用,iOS

标签 ios uiviewcontroller

我为 iOS 开发了应用程序,我 try catch 按钮中的事件,该按钮位于 xib 中,我在内部触摸时创建了一个方法。

我现在查看以下表格

DetailNoticiaController *detail = [[DetailNoticiaController alloc] init];
[self.view addSubview:detail.view];

detail.view包含按钮,当按下按钮时,应用程序崩溃并且不显示错误。

最佳答案

问题是 detail 会释放,因为您没有将它保存在某个地方。您可以尝试以下代码:

DetailNoticiaController *detail = [[DetailNoticiaController alloc] init];
[self addChildViewController:detail];
[self.view addSubview:detail.view];

有用的链接 - "Creating Custom Container View Controllers"

关于ios - View 中添加的事件按钮不起作用,iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19468823/

相关文章:

Swift 4 推送 viewController 而不是 Present

ios - 当使用手势关闭呈现的 View Controller 时如何获得通知?

objective-c - NSInvalidArgumentException - 接收者没有带有标识符的 segue

ios - 如何在没有 UITableViewController 的情况下在 UITableView 中显示原型(prototype) UITableViewCells?

ios - 如何在按下主页按钮后重置 ViewController 并返回到同一个 ViewController

ios - 同步还是异步获取userID(iOS)?

ios - 对 Transformable 属性采用 NSSecureUnarchiveFromDataTransformer 时发生崩溃

ios - 如何在不重新加载 Objective-C 行的情况下更改行中的特定元素?

ios - 如何在 Xcode 中运行 OAuthSwift 演示?

iOS:NSString 的可逆散列?