- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用了示例项目 AppPrefs 中的这一行:
UITableView *tableView = ((UITableViewController *)self.navController.visibleViewController).tableView;
它当然可以完美地工作,
所以我尝试了:
UISearchBar *searchBar = (UIViewController *)mySearchBar;
但我收到警告,mySearchBar
未声明,即使它是一个属性并在 MainViewController(属于 UIViewController 类)中初始化。
我需要从 AppDelegate 访问 MainViewController 中的各种对象,以便应用程序可以在设置更改时自行刷新。
最佳答案
哎呀,你的代码在尽可能多的地方都是错误的。让我解释一下哪里:
一个。您将 mySearchBar
转换为 UIViewController *
,然后将其分配给不同的指针类型(UISearchBar *
类型)。
两个。如果您是从应用程序委托(delegate)编写此代码,那么编译器为什么应该知道您正在使用哪个类(甚至更进一步,哪个对象的)属性?可能有多个对象/类具有相同名称的属性。
我觉得你混淆了类型转换和访问属性(所以我强烈建议在直接深入 iOS 开发之前正确学习纯 C,因为这是一个基本问题,如果你不这样做,你可能会生成低质量的代码了解这个)。您应该维护 View Controller 的实例(将其设为全局变量、单例,或者更好的是应用程序委托(delegate)对象的属性)并从那里访问它。示例:
UISearchBar *bar = [[[[UIApplication sharedApplication] delegate] mainViewController] searchBar];
关于ios 我想从 AppDelegate 访问 MainViewController 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11729129/
我只有一个 Objective-C 项目,我想使用 AppDelegate 访问我的 xcdatamodel,但是当我将 AppDelegate.swift 添加到我的项目时,它显示了一个编译问题,它
我正在编写一些代码。 import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, XP
我们可以通过这些方式使用 AppDelegate 的对象... 1) AppDelegate *app; // Globally declared app = (AppDelegate*)[[UIAp
我有一个像往常一样有 AppDelegate 的应用程序。我有一个 AppDelegate 的扩展,像这样: extension AppDelegate { func doSomething(
我的 appDelegate 中有两种类型的 var:int 和 NSMutableArray我可以访问 viewController 中的 int var,但无法访问 NSMutableArray
我创建了一个新项目并想将 App Delegate 从 AppDelegate 重命名为 FlickrAppDelegate。我想我在适当的地方重命名并且能够构建但我收到以下错误: 它构建正常,但显然
我正在尝试使用名为 AWSAppSync 的适用于 iOS 的 Amazon Web Serivces SDK。我发现good instructions for Swift 。我将尝试使问题更普遍地适
我在尝试设置自动登录功能时遇到问题。 我之前对根 ViewController 进行了一些研究,发现我现在需要使用 SceneDelegate 来实现自动登录功能,而不是使用 AppDelegate。
我注意到在默认使用 ARC 的最新版本的 Xcode 中,当您开始一个新项目时 Xcode 为您生成的 main.m 文件使用 NSStringFromClass([AppDelegate class
AppDelegate 它继承UIResponder , 并且实现了UIApplicationDelegate协议 。UIApplicationDelegate 协议中定义了很多app不同状态下触发的
当我将以下覆盖添加到 AppDelegate 时: public override void HandleAction(UIApplication application, string action
我正在设计一个相当大的应用程序,启动时它将与几个不同的服务器创建 session 。由于他们正在创建一个在应用程序的所有部分中使用的 session ,因此我认为在应用程序委托(delegate)中最
Xcode 中给出的 AppDelegates 方法到底是什么?我的应用程序中有很多类(class)。现在我想要的是我有 AudioStreamer 类,并且我必须在大多数其他类中使用该类...并且我
我没有整天都碰过AppDelegate.h文件,突然我收到3个错误... // AppDelegate.h #import //!Expected selector for Objective-
我知道没有必要保留委托(delegate),以避免保留循环。我在一次采访中碰巧遇到了一个问题,“如果保留了 appDelegate 会怎样?”。我对此没有答案,并根据我的知识在这里寻求答案。谢谢 最佳
我正在快速制作一个应用程序,但我遇到了一些问题。我正在尝试运行我的应用程序,但每次都会出现错误。 这是完整的错误: *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序
- (void)applicationDidFinishLaunching:(UIApplication *)application { NSError *error = nil;
在AppDelegate.h我创建了以下属性, @property (strong, nonatomic) NSMutableDictionary *googleUserDetailsDictiona
我正尝试按照 Ray Wenderlichs 教程在 cocos2d 游戏中使用 UIKit:How To Integrate Cocos2D and UIKit 但是我卡在了这一点上: Then,
我正在开发一个使用 CoreLocation 来管理 iBeacon 的 iOS 应用程序。我在 AppDelegate 和 ViewController 中都有 Beacon 检测,但我希望 App
我是一名优秀的程序员,十分优秀!