如果手机未连接到互联网,则加载不同的笔尖

发布于 2024-12-03 11:20:08 字数 1105 浏览 3 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

余生共白头 2024-12-10 11:20:08

您可以执行以下操作:

if ( ! isConnected )
{
    NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
    [self presentModalViewController:noConn animated:NO];
    [NoConnection release];
}

You can do the following:

if ( ! isConnected )
{
    NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
    [self presentModalViewController:noConn animated:NO];
    [NoConnection release];
}
日裸衫吸 2024-12-10 11:20:08

您提供的代码应该可以工作,问题一定出在 nib 链接的其他地方,您可能忘记将某些内容链接到 nib 文件。
试试这个

    [self.navigationController presentModalViewController:noConn animated:YES];  

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

    [self.navigationController presentModalViewController:noConn animated:YES];  
傻比既视感 2024-12-10 11:20:08

你的笔尖是否有NoConnection作为文件的所有者(我猜NoConnection是UIViewController的子类,检查一下。我将在下面调用这个NoConnectionViewController,因为你应该这样命名它,以免出错)?

文件的所有者视图属性是否与图形视图链接?检查一下。

您是否在窗口顶部没有状态栏的情况下工作?这可能是个问题。

你在 modalViewController 里面吗?如果是,您的代码将无法工作,您必须使用:

    NoConnectionViewController* nextWindow = [[NoConnectionViewController alloc]  initWithNibName:@"NoConnecton" bundle:nil];  // Check your nib name here, seems to be a mistake
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
    [self presentModalViewController:navController animated:YES];
    [navController release];
    [nextWindow release];

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 :

    NoConnectionViewController* nextWindow = [[NoConnectionViewController alloc]  initWithNibName:@"NoConnecton" bundle:nil];  // Check your nib name here, seems to be a mistake
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
    [self presentModalViewController:navController animated:YES];
    [navController release];
    [nextWindow release];
断念 2024-12-10 11:20:08

您需要使用警报视图的委托方法,

#pragma mark - AlertView Delegates

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1)
        {
            NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
            [self presentModalViewController:noConn animated:NO];
            [NoConnection release];
        }
}

不要忘记将alertView的标签值分配为1。

也不要忘记遵守UIAlertViewDelegate协议

快乐编码:)

You need to use the delegate method of alert view

#pragma mark - AlertView Delegates

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1)
        {
            NoConnection *noConn = [[NoConnection alloc] initWithNibName:@"NoConnecton" bundle:nil];
            [self presentModalViewController:noConn animated:NO];
            [NoConnection release];
        }
}

don't forget to assign tag value of alertView to 1.

and also dont forget to conforms to the UIAlertViewDelegate protocol

Happy Coding :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文