iOS方法声明问题

iOS方法声明问题,ios,objective-c,Ios,Objective C,这是.m文件 - (void)alertStatus { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Log In" message:@"Please enter your username and password"

这是.m文件

- (void)alertStatus {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Log In"
                                                        message:@"Please enter your username and password"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:nil];
    [alertView show];

}
导入
@界面ViewController:UIViewController
@属性(弱,非原子)IBOutlet UITextField*txtPassword;
@属性(弱、非原子)IBOutlet UITextField*txtUserName;
-(iAction)登录勾选:(id)发件人;
@结束

这是.h文件,有人能帮我理解如何声明这个方法吗。

不清楚你在问什么

您想拥有一个可以从外部调用的公共方法alertStatus吗

因此,只需在LoginClicked声明下方添加这一行:

    import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property (weak, nonatomic) IBOutlet UITextField *txtPassword;
    @property (weak, nonatomic) IBOutlet UITextField *txtUserName;


    - (IBAction) LoginClicked:(id)sender;

    @end
(请注意,方法名称应始终以小写字母开头,因此LoginClicked应命名为LoginClicked。)

请注意,对于要在ViewController中调用方法的任何类,都需要添加行

- (void)alertStatus;

在您的.m文件顶部。

这就是我尝试过的,它仍然说它未声明,这是因为它位于另一个名为“-(iAction)loginClicked”的方法中。因此,我要问的真正问题是,如何在另一个方法中声明一个方法?在另一个方法中声明一个方法?你没有。我能想到的唯一支持本地函数的语言是PASCAL,自从MacOS7以来我就没有用PASCAL编程过。在您试图调用alertStatus的地方发布代码,以及如何为视图控制器导入标题。@Duncac,许多语言都允许使用嵌套函数:Ruby、Python、Scala。使用语言扩展甚至是C。我现在已经解决了,Duncan,在方法中调用我的方法是不正确的。直到我仔细研究了程序背后的逻辑,我才意识到这一点。谢谢你的帮助=]你能对你的问题发表一个答案,解释什么是错的,然后接受你自己的答案吗?
#import "ViewController.h"