2014-11-23 84 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