我在我的应用程序的同一视图中使用界面生成器制作了三个按钮。我希望每个按钮执行单独的 IBAction,但是当我尝试执行
- (IBAction)button:(id)sender {
if([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable) {
[self.textfield resignFirstResponder];
self.translation.text = @"Sorry, you need an internet connection to translate.";
}
else {
// Connected to the internet
[self.textfield resignFirstResponder];
NSString *toTranslate = self.textfield.text;
NSString *url = [NSString stringWithFormat:@"http://www.archives.nd.edu/cgi-bin/wordz.pl?keyword=%@", toTranslate];
NSURL *translationUrl = [NSURL URLWithString:url];
NSData *translationHtmlData = [NSData dataWithContentsOfURL:translationUrl];
TFHpple *translationParser = [TFHpple hppleWithHTMLData:translationHtmlData];
NSString *translationXpathQueryString = @"/html/body/pre";
NSArray *translationOutput = [translationParser searchWithXPathQuery:translationXpathQueryString];
NSString *translatedString = ((TFHppleElement *)translationOutput[0]).firstChild.content;
self.translation.text = translatedString;
}
}
@implementation
它在 viewcontroller.m上给出了“找不到‘按钮’的方法定义”警告。
我用这种方法做错了什么还是有更好的方法?