我写的脚本中有错误,错误是:
控制到达非空函数的结尾
这是我的代码:
-(BOOL) hasInternet {
Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.co.uk"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable){
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"Internet" message:@"is DOWN" delegate:self cancelButtonTitle:@"Turn on your Internet" otherButtonTitles:@"Cancel",nil];
[alertOne show];
}
}
谁能看到我哪里出错?
答案 0 :(得分:1)
您的方法旨在使用return语句返回布尔值,例如return YES;
。
由于您尚未实现此类操作,因此该方法无法成功编译。如果要返回BOOL
,可以添加return语句。如果您不想返回BOOL
,只需更改方法初始化:
-(void) hasInternet {
Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.co.uk"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable){
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"Internet" message:@"is DOWN" delegate:self cancelButtonTitle:@"Turn on your Internet" otherButtonTitles:@"Cancel",nil];
[alertOne show];
}
}