标签: viewcontroller

从通知打开应用程序时打开特定视图

我刚刚向我的应用添加了推送通知.我想要这样,当用户从通知中打开应用程序时,它将打开一个特定的视图控制器,而不是我的rootViewController.这是我的AppDelegate:

#import "KFBAppDelegate.h"
#import "KFBViewController.h"
#import "AboutUs.h"
#import "ContactUs.h"
#import "KYFB.h"
#import "KFBNavControllerViewController.h"
#import "KFBTabBarViewController.h"
#import "RSFM.h"
#import "LegislatorInfo.h"
#import "Events.h"
#import "ActionAlertsViewController.h"
#import "UAirship.h"
#import "UAPush.h"
#import "UAAnalytics.h"

@implementation KFBAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // This prevents the UA Library from registering with UIApplcation by default when
    // registerForRemoteNotifications is called. This will allow you to prompt your
    // users at a later time. This gives your app the opportunity to explain the benefits
    // of push …
Run Code Online (Sandbox Code Playgroud)

push-notification viewcontroller ios

21
推荐指数
2
解决办法
4万
查看次数

的setValue:forUndefinedKey:]:

FinalViewWithSending *newView = [[FinalViewWithSending alloc]initWithNibName:@"FinalViewWithSending" bundle:nil];
newView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newView animated:YES]; //it crashes here with a thread 1 error, SIGABRT error..
Run Code Online (Sandbox Code Playgroud)

它说:

"Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<FinalViewWithSending 0x1bef70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButton.'"
Run Code Online (Sandbox Code Playgroud)

没有名为loginButton的变量,所以我不知道为什么我会收到错误...

谢谢

xcode viewcontroller sigabrt modalviewcontroller

20
推荐指数
4
解决办法
3万
查看次数

删除类丢弃错误消息未知>:0:错误:没有这样的文件或目录:

所以我和一些朋友在一个bitbucket项目上工作,并且已经意识到bitbucket有时不会同步所有文件.但这是发生了什么:

我继续工作并创建了一个类,我基本上复制了一个旧的View Controller(称为WelcomescreenViewController.swift- > CreateAccountViewController.swift)并在主故事板中进行了一些调整.在这里,我删除了新的所有旧插座,然后为ViewController创建了一个自己的类,并在主故事板中将它与它连接起来.

现在发生的是有一些问题,我还原了一切,并再次删除了这两件事.基本上现在Xcode仍然认为应该有类.它总是丢弃消息:

在此输入图像描述

我还使用我的文件从目录中截取屏幕截图,如下所示:

在此输入图像描述

我试图再次创建该类,以便Xcode很高兴,但它没有帮助.文件是在某个地方链接的,或者我该怎么做,教Xcode嘿,一切都很好,不介意旧文件CreateAccountViewController.swift

xcode bitbucket viewcontroller ios swift

19
推荐指数
1
解决办法
4063
查看次数

了解在iOS中查看控制器嵌套

在过去的几天里,我一直在试着理解这个看似基本的iOS开发概念:

  • 如果我想在同一个"屏幕"中显示和使用两个或更多View Controller,请执行以下操作:

    1. 根据Apple的"每个屏幕内容只有一个VC",这是不可取的
    2. 通过代码添加VC完全可以实现
    3. 没做完.相反,使用一个VC并简单地添加模仿所需视图控制器功能的代码.

让我重新说一下:

如果我想在一个iPad应用程序中,UIView(A)占据屏幕左侧的大部分,而第二个UIView(B)占据屏幕右侧的其余部分,我想要向UIViewB 添加一个按钮,当点击它时会使用模态转换来向上滑动UITableview以替换UIView B,这UITableview将是一个典型的行为UITableviewController,当用户从表中选择一个项目时,典型的事件将被发送到tableview控制器推送一组新项目,这可能吗?

在我看来,如果我已经能够轻松地创建两个单独的UIViewControllers,并且在一个VC中有一个按钮以模态方式调出第二个VC,为什么我不能将这个功能结合起来,这样一个VC有两个子VC,那些孩子VC处理自己的模态转换.

或者在这种情况下最好的做法就是只需要一个VC来处理所有内容,然后在对各种UI元素进行各种点击后手动处理各种视图中的幻灯片动画?

正如你所知道的那样,我认为我已经阅读了太多不同的,相互矛盾的对类似问题的回答,我已经完全混淆了什么了.如果有人在那里了解我得到了什么,可以提供帮助解释或一些指示我非常欣赏它.

cocoa nested interface viewcontroller ios

17
推荐指数
2
解决办法
1万
查看次数

iOS - 工具栏未显示

使用故事板我为第二个View控制器创建了一个新屏幕,并在底部添加了一个工具栏.但是当显示视图时,工具栏不会出现.我正在使用Segue改变观点.

可能有什么不对?

toolbar storyboard viewcontroller ios segue

17
推荐指数
2
解决办法
2万
查看次数

如何在iOS中按"返回"按钮时创建确认弹出窗口?

当有人按下我的iOS应用程序的"后退"按钮时,我想添加一个弹出窗口,询问用户他是否真的想回来.然后,根据用户的响应,我想撤消操作或继续.我试图在我的视图的viewWillDisappear函数中添加代码然后编写正确的委托但它不起作用,因为它总是更改视图然后显示弹出窗口.我的代码是:

    -(void) viewWillDisappear:(BOOL)animated {
       _animated = animated;
       if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
           UIAlertView *alert_undo = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
                                                                message:@"You could be    loosing information with this action. Do you want to proceed?"
                                                               delegate:self
                                                      cancelButtonTitle:@"Go back"
                                                      otherButtonTitles:@"Yes", nil];
           [alert_undo show];
       }
       else [super viewWillDisappear:animated];
   }
Run Code Online (Sandbox Code Playgroud)

代表实现是:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Yes"])
    {
        [super viewWillDisappear:_animated];
    }
}
Run Code Online (Sandbox Code Playgroud)

这根本不起作用.现在有人有更好的方法去做或可能出错吗?

非常感谢你,

objective-c popup viewcontroller ios

17
推荐指数
2
解决办法
2万
查看次数

Swift:如何从View控制器访问AppDelegate变量?

我想在文本或csv(prefer)文件中写入视图控制器中的变量.

事实上,我正在做一个绘图应用程序,我想在文件中写下手指的当前位置.

class ViewController: UIViewController {var lastPoint = CGPoint.zeroPoint ... }
Run Code Online (Sandbox Code Playgroud)

我想从AppDelegate访问lastPoint.x和lastPoint.y.我怎么能这样做?谢谢.

viewcontroller appdelegate swift

17
推荐指数
1
解决办法
3万
查看次数

类没有初始值设定项:Swift Error

我的ViewController有问题.

我的代码有关于初始化程序的错误,我无法理解为什么.

请花一点时间查看我的代码:

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

let sectionsTableIdentifier = "SectionsTableIdentifier"

var names: [String: [String]]!
var keys: [String]!

@IBOutlet weak var tableView: UITableView!

var searchController: UISearchController

//methods
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: sectionsTableIdentifier)

    let path = NSBundle.mainBundle().pathForResource("sortednames", ofType: "plist")

    let namesDict = NSDictionary(contentsOfFile: path!)
    names = namesDict as! [String: [String]]
    keys = namesDict!.allKeys as! [String]
    keys = keys.sort()

    let resultsController = SearchResultsController() …
Run Code Online (Sandbox Code Playgroud)

viewcontroller ios swift

17
推荐指数
1
解决办法
2万
查看次数

如何解除当前的ViewController并转到Swift中的另一个View

我是Swift的新手,我想知道如何关闭当前的视图控制器并转到另一个视图.

我的故事板如下所示:MainMenuView - > GameViewController - > GameOverView.我想解雇GameViewController转到GameOverView,而不是MainMenuView.

我在MainMenuView中使用以下代码:

@IBAction func StartButton(sender: UIButton) {
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameViewController") as! GameViewController
    self.presentViewController(nextViewController, animated:true, completion:nil)
    restGame()
}
Run Code Online (Sandbox Code Playgroud)

在GameViewController中,我使用此代码,但它不会忽略GameViewController.

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameOverView") as! GameOverView
self.presentViewController(nextViewController, animated:true, completion:nil)
Run Code Online (Sandbox Code Playgroud)

这是我的GameOverView代码:

class GameOverView: UIViewController{
    // save the presenting ViewController
    var presentingViewController :UIViewController! = self.presentViewController

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func ReplayButton(sender: UIButton) {
        restGame()
        didPressClose()
    }
    @IBAction …
Run Code Online (Sandbox Code Playgroud)

viewcontroller ios segue swift

15
推荐指数
1
解决办法
4万
查看次数

Swift 3,Xcode 8实例化View Controller无法正常工作

编译时的Xcode 8表示viewcontroller用标识符简单地更改实例化,实例化视图控制器.我这样做了,为什么会出现两个错误?

我正在使用Swift 3.我想以编程方式更改页面.我已经阅读了很多关于该主题的其他问题.所有这些都使用带有标识符的实例化视图控制器.他们没有采用新语言.

@IBAction func switchPage(_ sender: UIButton) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let viewController = 
storyboard.instantiateViewController("secondViewController") as! 
UIViewController
    self.presentViewController(secondViewController, animated: true, 
completion: nil)    

}
Run Code Online (Sandbox Code Playgroud)

谢谢.我按照建议改变了代码,只收到一个错误:可选类型'UIStoryboard?'的值 没有打开; 你的意思是用'!' 要么 '?'?我应该在某处添加感叹号吗?

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a 
nib.
}

@IBAction func ch(_ sender: UIButton) {



    let viewController = 
storyboard.instantiateViewController(withIdentifier: 
"secondViewController") as! UIViewController
    self.present(viewController, animated: true)



}




override func …
Run Code Online (Sandbox Code Playgroud)

storyboard viewcontroller swift swift3 xcode8

15
推荐指数
2
解决办法
3万
查看次数