2014-11-23 85 views
-2
- (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文件iOS的方法声明的烦恼

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文件,能有人帮助我了解如何声明这个方法吧。

+0

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html – 2014-11-23 22:36:52

回答

0

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

你想有一个公共方法alertStatus可以从外部调用?

所以才加入这行只是LoginClicked的声明如下:(注意,方法名应该总是以小写字母开头,所以LoginClicked应该命名为loginClicked)

- (void)alertStatus; 

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

#import "ViewController.h" 

在.m文件的顶部。

+0

这就是我试过的,它仍然说它是未申报的,这是因为它是在另一种称为“ - (IBAction)loginClicked”的方法中。因此,我所问的真正问题是如何在另一种方法中声明一种方法? – 2014-11-23 22:41:59

+0

另一种方法内的方法?你没有。我能想到的唯一一种支持本地函数的语言是PASCAL,并且自Mac OS 7以来我没有在Pascal中进行编程。在您尝试调用alertStatus的地方发布代码,以及如何为视图导入标题控制器。 – 2014-11-23 23:02:36

+0

@DuncanC,许多语言都允许嵌套函数:Ruby,Python,Scala。与语言扩展甚至C. – vikingosegundo 2014-11-23 23:38:58