私が開発しているプログラムではUtilities
、キャンセル ボタンのあるアラート ビューを含むクラスを作成しました。キャンセル ボタンが押されたときに通知する NSLog を 1 つ作成したいと考えています。アラート ビューを含むメソッドは、ViewController.m ファイルである別のクラスで呼び出されますが、現時点ではログは表示されません。私が間違っていることを理解するのを手伝ってもらえますか?
これは Utilities.h ファイルです。
@interface Utilities : UIViewController <UIAlertViewDelegate>
-(BOOL) isOnline;
@end
これは Utilities.m ファイルです。
-(BOOL) isOnline {
Boolean online = false;
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == ReachableViaWiFi) {
NSLog(@"WI FI");
online = true;
} else {
NSLog(@"NO WI FI");
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Warning"
message:@"You are not connected to a wireless network. Please connect your device."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
return online;
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex::(NSInteger)buttonIndex
{
if(buttonIndex==alertView.cancelButtonIndex) {
NSLog(@"Clicked the button Ok");
}
}
そして、ViewController
クラスでメソッドを呼び出す場所は次のとおりです。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Add gradient background
CAGradientLayer *bgLayer = [BackgroundLayer blueGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
[self initialize];
Utilities* utilities = [[Utilities alloc] init]; //create an istance of the class Utilities for use their methods in this class
[utilities isOnline]; //call the method isOnline from the class Utilities
}
更新: ここに、Xcode に返されるエラー メッセージがあります。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x7558670' *** First throw call stack: (0x1809012 0x162ee7e 0x18944bd 0x17f8bbc 0x17f894e 0xb30e13 0x778d66 0x778f04 0x2027d8 0x1dd4014 0x1dc47d5 0x17afaf5 0x17aef44 0x17aee1b 0x268f7e3 0x268f668 0x73affc 0x2133 0x20c5) libc++abi.dylib: 例外をスローして呼び出された終了"