[EDIT1]
在你的viewController頭:
@interface ViewController : UIViewController <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityind;
@property (weak, nonatomic) IBOutlet UITextField *search;
-(void)doSomeWork;
-(IBAction)calculate:(id)sender;
@end
簡單地實現在二線程序的功能。
在你viewController.m文件:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
if(search == textField){
[textField resignFirstResponder];
[self doSomeWork];
}
return YES;
}
-(void)doSomeWork{
// Do whatever you want to do here!!!
}
-(IBAction)calculate:(id)sender{
[self doSomeWork];
}
在你的XIB文件,你將不得不按鈕連接到「計算」行動,搜索到正確的UITextField。
您可以在界面生成器或代碼中以圖形方式設置UITextField的委託。如果代碼,那麼你的viewController.m文件中添加一行:
search.delegate = self;
您viewDidLoad方法如下:
-(void)viewDidLoad{
[super viewDidLoad];
search.delegate = self;
}
在viewcontroller.m?如果是這樣,我已經有了,見下: - (IBAction)計算:(id)發件人{ //隱藏鍵盤 [search resignFirstResponder]; NSString * query2 = [search.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@「http://www.mathcelebrity.com/namesearch.php?searchInput=%@」,query2]]; NSURLRequest * request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; NSTimer * timer; NSTimer * timer; } – 2012-07-17 03:02:11
計算是按鈕按下事件。我期待有相同的例程調用,如果有人按下名稱搜索的uitextfield輸入沒有按計算按鈕 – 2012-07-17 03:11:51
我想我理解,查看我的編輯 – 2012-07-17 03:26:30