现在项目正在使用App委托类中的MainWindow.xib作为主nib文件.它在main.m文件中有这个代码
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
我想用Mainstoryboard替换它.我在info.plist文件中将其更改为Mainstoryboard文件基本名称,但它显示没有设置app delegate的错误.必须指定应用程序委托类才能使用主故事板文件.
我应该在App委托类中使用什么编码来使用Mainstoryboard文件.
谢谢
最近我开始知道"你真的不应该调用AppDelegate来获取托管对象上下文".苹果公司也已经把这个建议到他们的文档在这里.它是这样的:
视图控制器通常不应从全局对象(例如应用程序委托)检索上下文 - 这会使应用程序体系结构变得僵硬.视图控制器也不应为自己的用途创建上下文(除非它是嵌套的上下文).这可能意味着使用控制器上下文执行的操作未在其他上下文中注册,因此不同的视图控制器将对数据具有不同的视角.
此外,他们还提到了其他一些获取背景的方法.到目前为止,我无法弄清楚他们在那里想说些什么.任何人都可以对这个问题有所了解.任何支持语句的代码片段都是最受欢迎的.
编辑
但是,有时从应用程序或文档或视图控制器以外的其他位置检索上下文更容易或更合适.您可能在基于Core Data的应用程序中使用的几个对象保留对托管对象上下文的引用.托管对象本身具有对其自身上下文的引用,支持Core Data的各种控制器对象(如阵列和对象控制器)(OS X中的NSArrayController和NSObjectController以及iOS中的NSFetchedResultsController)也是如此.
从其中一个对象中检索上下文的优点是,如果重新构建应用程序,例如使用多个上下文,则代码可能仍然有效.例如,如果您有一个托管对象,并且想要创建与其相关的新托管对象,则可以向原始对象询问其托管对象上下文并使用该对象创建新对象.这将确保您创建的新对象与原始对象位于相同的上下文中.
究竟是什么?我确定它与下面的Highly投票答案不相似.有人可以帮我理解这部分Apple文档吗?
core-data objective-c nsmanagedobjectcontext ios appdelegate
我试图在用户单击UILocalNotification时从swift中的app delegate加载特定的ViewController.我已经发现在这个函数中调用了它:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问其中一个打开的ViewControllers时,我认为它返回null,因为我的应用程序正在崩溃.这是我正在尝试的:
var rootViewController = self.window!.rootViewController
var storyBoard = rootViewController.storyboard
var setViewController = storyBoard.instantiateViewControllerWithIdentifier("CurrentShows") as ViewController_CurrentShows
rootViewController.navigationController.popToViewController(setViewController, animated: false)
setViewController.reloadData()
Run Code Online (Sandbox Code Playgroud)
它在popToViewController行崩溃了.
我正在开发一个需要推送通知的iPhone应用程序.我按照说明创建了认证并修改了应用ID.我并不完全确定我这样做是正确的,但我的确遵循了指示.知道如何检查这是否正常?
当我在模拟器中运行时,我收到一条错误消息,指出模拟器不支持推送通知.这有点预期.
顺便说一下:我有几次看似这个问题.它总是似乎是一个破牢的手机.我的手机没有被囚禁.
但是当我在iPhone上调试时,didRegisterForRemoteNotificationsWithDeviceToken方法永远不会被触发.我真的很感激一些帮助.我的代码如下.
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
rootController.delegate = self;
[window addSubview:rootController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str =
[NSString stringWithFormat:@"%@",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(str);
}
Run Code Online (Sandbox Code Playgroud) 我想在文本或csv(prefer)文件中写入视图控制器中的变量.
事实上,我正在做一个绘图应用程序,我想在文件中写下手指的当前位置.
class ViewController: UIViewController {var lastPoint = CGPoint.zeroPoint ... }
Run Code Online (Sandbox Code Playgroud)
我想从AppDelegate访问lastPoint.x和lastPoint.y.我怎么能这样做?谢谢.
我想知道App Delegate的功能.它有一些很好的方法,比如-applicationDidFinishLaunching应用程序完成启动时会调用,等等.但究竟是什么呢?是否在UIApplicationMain函数中实例化了一些对象?
我的应用程序中的每个类都可以访问该App Delegate对象,它是如何工作的?网上是否有任何可视化这些关系的好图表?
delegates uiapplication uiapplicationdelegate ios appdelegate
在PushKit中提到我们可以使用常规推送或VoIP推送.但我没有找到任何PKPushType用于常规推送的文档.有没有人尝试使用PushKit定期推送?如果我不使用VoIP,如果收到推送通知,可以在后台启动被杀应用程序吗?这意味着如果应用程序被杀死并且通知出现并且用户没有对其采取行动,那么如果我使用PushKit,iOS可以在后台启动应用吗?
push-notification apple-push-notifications ios appdelegate ios8
我想知道我是否可以从另一个ViewController调用app delegate方法.
当应用程序启动时,将application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool调用i方法.我可以从另一个视图控制器再次调用此方法吗?
当我从主viewController重定向到另一个viewController时,我得到了这个
错误:
懒加载NSBundle MobileCoreServices.framework,
加载MobileCoreServices.framework,
对于systemgroup.com.apple.configurationprofiles路径系统组容器是/用户/开发/库/开发商/ CoreSimulator /设备/ 083C0102-C85F-463A-96F4-CA1B9AC7919D /数据/容器/共享/ SystemGroup/systemgroup.com.apple. configurationprofiles
我的代码是......
Appdelegate.m
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Launched first time");
} else {
NSLog(@"Already launched");
[self getData];
}
Run Code Online (Sandbox Code Playgroud)
viewDidLoad中
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) {
dispatch_async(dispatch_get_main_queue(), ^{
LoginPageViewController *lpvc = [self.storyboard instantiateViewControllerWithIdentifier:@"LPVC"];
[self.navigationController pushViewController:lpvc animated:NO];
});
} else {
// My code...
}
Run Code Online (Sandbox Code Playgroud) 我需要将一个变量从AppDelegate传递给另一个我创建的类来保存项目的全局变量,我无法找到使其工作的方法.
这是AppDelegate中的代码:
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
println("Device's token is: \(deviceToken)")
//Global Variables Class Instance
let globals:Globals = Globals()
globals.setDeviceToken("test1") //method1 not working
globals.deviceToken = "test2" //method2 not working
}
Run Code Online (Sandbox Code Playgroud)
这是我的Globals类:
public class Globals {
var deviceToken = String()
init() {
//nothing
}
func setDeviceToken(s:String){
deviceToken = s
}
func getDeviceToken() -> String {
return deviceToken
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试从项目的其他文件打印值,我将无法获得任何内容,只是一个空字符串.
class ViewController: UIViewController {
//Global Variables Class Instance
let globals:Globals = Globals()
override func viewDidLoad() {
println(globals.getDeviceToken()) //return empty …Run Code Online (Sandbox Code Playgroud) appdelegate ×10
ios ×8
swift ×4
iphone ×2
objective-c ×2
core-data ×1
delegates ×1
devicetoken ×1
ios8 ×1
xcode9 ×1