如果手机未连接到互联网,则加载不同的笔尖
我使用 Apple 的 Reachability 类,它工作正常,使用警报告诉用户连接不可用或连接丢失。但是,我想将警报更改为更直观的内容。我想加载一个笔尖,告诉用户不存在活动连接,但笔尖未加载。我也尝试加载其他笔尖,但它也没有加载笔尖。
- (BOOL) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"You are currently not connected to a WI-FI or cellular Data.\nPlease make sure you are connected." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
//NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
//[self presentModalViewController:noConn animated:NO];
//[NoConnection release];
self.isConnected = NO;
return NO;
break;
}
//more cases.........
警报部分工作正常,但加载笔尖的部分则不然。你能告诉我这里出了什么问题吗?我在 viewWillAppear 中调用这个函数。谢谢!
I use Apple's Reachability class and it's working fine using an alert to tell the user that the connection is not available or the connection is lost. However, I want to change the alert to something more visual. I want to load a nib that tells the user no active connection is present but the nib is not loading. I also tried loading my other nibs but it also doesn't load the nib.
- (BOOL) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Internet Connection" message:@"You are currently not connected to a WI-FI or cellular Data.\nPlease make sure you are connected." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
//NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
//[self presentModalViewController:noConn animated:NO];
//[NoConnection release];
self.isConnected = NO;
return NO;
break;
}
//more cases.........
the alert part is working just fine but the part for loading the nib is not. can you tell me whats wrong here? I'm calling this function in viewWillAppear. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以执行以下操作:
You can do the following:
您提供的代码应该可以工作,问题一定出在 nib 链接的其他地方,您可能忘记将某些内容链接到 nib 文件。
试试这个
The code you have presented should work, sow the problem must be somewhere else probably in the nib - linking, you might have forgot to link something to the nib file.
try this
你的笔尖是否有NoConnection作为文件的所有者(我猜NoConnection是UIViewController的子类,检查一下。我将在下面调用这个NoConnectionViewController,因为你应该这样命名它,以免出错)?
文件的所有者视图属性是否与图形视图链接?检查一下。
您是否在窗口顶部没有状态栏的情况下工作?这可能是个问题。
你在 modalViewController 里面吗?如果是,您的代码将无法工作,您必须使用:
Does your nib has NoConnection as a File's Owner (I guess NoConnection is a subclass of UIViewController, check it. I'll call this NoConnectionViewController bellow because you should name it like that for no mistake) ?
Is the file's owner view property linked with the graphical view ? Check it.
Are you working without status bar at top of the window ? That could be a problem.
Are your here inside a modalViewController ? If yes, your code won't work, you must use instead :
您需要使用警报视图的委托方法,
不要忘记将alertView的标签值分配为1。
也不要忘记遵守
UIAlertViewDelegate
协议快乐编码:)
You need to use the delegate method of alert view
don't forget to assign tag value of alertView to 1.
and also dont forget to conforms to the
UIAlertViewDelegate
protocolHappy Coding :)