Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 如何更改设置标题按钮?_Ios7_Uibutton_Storyboard - Fatal编程技术网

Ios7 如何更改设置标题按钮?

Ios7 如何更改设置标题按钮?,ios7,uibutton,storyboard,Ios7,Uibutton,Storyboard,1) 我有一个视图控制器文件,它有一个按钮,我想在从app委托调用didFinishedLaunching方法时更改按钮标题 我还初始化了控制器,但没有改变 提前感谢。要正确设置标题: 编辑:如果您希望在更改AppDelegate后更新视图状态,那么最好使用。在app delegate中,您可以发布有关用户登录或注销的通知,然后可以将viewController配置为通知的观察者,并在发出通知时更新其状态 例如,在您的应用程序中 UIButton *loginButton = [self.l

1) 我有一个视图控制器文件,它有一个按钮,我想在从app委托调用didFinishedLaunching方法时更改按钮标题

我还初始化了控制器,但没有改变


提前感谢。

要正确设置标题:


编辑:如果您希望在更改AppDelegate后更新视图状态,那么最好使用。在app delegate中,您可以发布有关用户登录或注销的通知,然后可以将viewController配置为通知的观察者,并在发出通知时更新其状态

例如,在您的应用程序中

UIButton *loginButton = [self.loginViewController LoginButton];
loginButton.titleLabel.text=@"Log out";

//[loginButton setTitle:@"Log out" forState:UIControlStateNormal];

 NSLog(@"Log in :-%@",loginButton.titleLabel.text);
然后在您的loginViewController中

- (void)userDidLogOut
{
    //This method would be called when you logout
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didLogoutNotification" object:nil];
}

您何时调用上述代码的可能重复?登录按钮是零吗?如果是,我猜它不是在
self.loginViewController
中初始化的,或者
self.loginViewController
本身是零?也许你应该把它注销并更新我知道如何编程的问题。但我的问题是,我有一个视图控制器,它有一个按钮,我想更改应用程序代理文件的标题@AnoopVaidyaus引用该按钮或通过delegate@user3400485检查我的UpdateYeah…这是正确的,但也检查loginButton是否初始化,因为它返回nil。请提供一点解释。只有代码的答案不受欢迎,会自动标记以供管理员批准。。我现在已经在原来的问题中添加了一条注释,因为很难确定为什么标题标签文本是nil而不是空字符串。我初始化了,但没有任何更改@liamnicholsi做这个代码,但它不适合我@连翘酚
- (void)viewDidLoad
{
    //...

    //Become an observer of `didLogoutNotification`.
    [[NSNoficationCenter defaultCenter] addObserver:self selector:@selector(didLogoutNotification:) name:@"didLogoutNotification" object:nil];
}

- (void)dealloc
{
    //...

    //Remove yourself from the observation list.
    [[NSNoficationCenter defaultCenter] removeObserver:self];
}

- (void)didLogoutNotification:(NSNotification *)notification
{
    //...

    //Update the button
    [loginButton setTitle:@"Log In" forState:UIControlStateNormal];
}