iOS方法声明麻烦

时间:2014-11-23 22:26:14

标签: ios objective-c

- (void)alertStatus {

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

}

这是.m文件

    import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

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


    - (IBAction) LoginClicked:(id)sender;

    @end

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

1 个答案:

答案 0 :(得分:0)

目前尚不清楚你在问什么。

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

所以只需在LoginClicked声明下方添加此行:

- (void)alertStatus;

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

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

#import "ViewController.h" 

位于.m文件的顶部。

相关问题