我要做的是单击一个按钮(在代码中创建)并让它调用一个不同的视图控制器,然后让它在新的视图控制器中运行一个函数.
我知道它可以在IB中相对容易地完成,但这不是一个选择.
我想要做的一个例子是,如果你有两个视图控制器,一个带有闪屏的房子.另一个视图控制器在房子上走过,你可以按照设定的顺序通过所有房间.启动画面会有每个房间的按钮,可以让你跳到步行的任何一点.
我正在尝试将我的Swift应用程序中的状态栏颜色更改为白色,但是我碰到了一堵砖墙.我有3个ViewControllers,每个都嵌入在NavigationController中(可能是问题吗?我已经尝试将代码放在NavigationController类中.)我在AppDelegate的didFinishLaunchingWithOptions中尝试了以下两段代码. .swift文件,但都没有工作.
application.statusBarStyle = .LightContent
Run Code Online (Sandbox Code Playgroud)
和
UIApplication.sharedApplication().statusBarStyle = .LightContent
Run Code Online (Sandbox Code Playgroud)
Docs关于它的所有内容都是UIBarButtonStyle是一个Int并且给了我这个enum片段,这对我来说并没有任何帮助.
enum UIStatusBarStyle : Int {
case Default
case LightContent
case BlackOpaque
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在处理推送通知.我编写了以下代码来获取设备令牌.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"This is device token%@", deviceToken);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error %@",err);
}
Run Code Online (Sandbox Code Playgroud)
我能够在设备上成功运行应用程序,但无法在控制台上获取设备ID.
我对认证和配置文件没有任何问题.
iphone push-notification apple-push-notifications ios appdelegate
我正在尝试创建推送通知,根据从推送获得的信息确定要打开的视图.
我已经设法从推送中获取信息,但我现在正在努力让视图打开
查看其他堆栈溢出问题,我目前有以下内容:
App Delegate完成加载:
//Extract the notification data
if let notificationPayload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
// Get which page to open
let viewload = notificationPayload["view"] as? NSString
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
//Load correct view
if viewload == "circles" {
var viewController = self.window?.rootViewController?.storyboard?.instantiateViewControllerWithIdentifier("Circles") as! UIViewController
self.window?.rootViewController = viewController
}
}
Run Code Online (Sandbox Code Playgroud)
目前这在var ViewController = self ...行上失败了.
在我的AppDelegate中有一个我不明白的问题.RootViewController最初调用了ViewController,我改名了.该应用程序由许多ViewController组成,然后我介绍了一个UINavigationController.为什么会出现此错误?
NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle
/Users/XXXXXXXXXXXX/Library/Application Support/iPhone simulator/6.0/Applications/
B7A7D461-1CFE-4B05-AF32-00B65FCFFF49/XXXXXXXXXX.app> (loaded)'with name
'RootViewController''
*** First throw call stack:
(0x1992012 0x1357e7e 0x1991deb 0x4bafac 0x37fe37 0x380418 0x380648 0x380882 0
x380b2a 0x397ef5 0x397fdb x398286 0x398381 0x398eab 0x398fc9 0x399055 0x49e3ab
0x2ef92d 0x136b6b0 0x1f12fc0 0x1f0733c 0x1f12eaf 0x38e8cd 0x2d71a6 0x2d5cbf
0x2d5bd9 0x2d4e34 0x2d4c6e 0x2d5a29 0x2d8922 0x382fec 0x2cfbc4 0x2cfdbf
0x2cff55 0x2d8f67 0x2b30 0x29c7b7 0x29cda7 0x29dfab 0x2af315 0x2b024b 0x2a1cf8
0x1dbedf9 0x1dbead0 0x1907bf5 0x1907962 0x1938bb6 0x1937f44 0x1937e1b 0x29d7da
0x29f65c 0x269d 0x25c5)
ibc++abi.dylib: terminate called throwing …Run Code Online (Sandbox Code Playgroud) 我正在做Facebook集成教程,如果用户有当前状态的有效令牌,我想显示我的MainViewViewController,否则我想显示LoginViewController.
MainViewAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// To-do, show logged in view
} else {
// No, display the login page.
[self showLoginView];
}
return YES;
}
- (void)showLoginView
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginViewController* loginViewController = [mainstoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.window.rootViewController presentViewController:loginViewController animated:YES completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
控制台错误:
Warning: Attempt to present <LoginViewController: 0xb492fd0> on <MainViewViewController: 0xb1bd820> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)
我不想使用NavigationController.
我正试图UIAlertController在我的iOS应用程序中呈现AppDelegate.以下是警报和本方法.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:cTitle message:cMessage preferredStyle:UIAlertControllerStyleAlert];
//Configure alert and actions
[self.window.rootViewController presentViewController:alert animated:TRUE completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试显示警报时,它不会出现,我在控制台中收到以下警报.
Warning: Attempt to present <UIAlertController: 0x145f5d60> on <UINavigationController: 0x146590f0> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)
导致错误的原因是什么?如何解决?
一旦我收到推送通知并轻扫以打开它,它就会打开我的应用而不是我想要的VC.
所以我的问题是如何加载我想要的VC?我知道如果应用程序是打开的,我会将VC移到另一个内部,didReceiveRemoteNotification但如果应用程序未打开,我该怎么做?或者它是否处于后台模式?
此外,我有两个不同的推送通知,因此我需要它移动两个不同的VC中的一个.如何区分不同的推送通知?
谢谢.
我想在用户点击收到的推送通知消息时打开特定的视图控制器,但是当我收到推送通知消息并单击该消息时,只打开应用程序,但它不会重定向到特定的视图控制器.
我的代码是
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (applicationIsActive) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bildirim"
message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
UIViewController *vc = self.window.rootViewController;
PushBildirimlerim *pvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"PushBildirimlerim "];
[vc presentViewController:pvc animated:YES completion:nil];
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题与iOS推送通知有关.
appdelegate ×10
ios ×8
objective-c ×3
swift ×2
cocoa-touch ×1
facebook ×1
ios6 ×1
iphone ×1
nib ×1
react-native ×1
uistatusbar ×1
xcode ×1
xcode6 ×1