0

我从必须使用 Reveal 控件的新 iOS 应用程序开始。所以我打算使用很棒的 ZUUIRevealController 库。我刚刚为 2-3 个屏幕创建了 UI。在其中一个屏幕中,我必须显示 UIAlertView 和 UIActionsheet。但我意识到UIAlertView & UIActionsheet 显示非常缓慢(它首先添加黑色叠加层,然后显示 UIAlertView/UIActionsheet,显示时会挂起某种警报视图。动画不流畅)。我没有添加任何编码逻辑,只是创建了 UI。我没有使用任何后台线程/dispatch_asyn()。所以不存在从后台线程更新 UI 的问题。所以我检查了内存泄漏和分配。我没有看到任何内存泄漏,但是当我显示菜单并推送新的视图控制器时,内存分配不断增加。当我弹出视图控制器时它不会减少。以下是截图:

1) 应用启动时 在此处输入图像描述

2)一段时间后,当我推送新的视图控制器时,弹出视图控制器

在此处输入图像描述

我知道每次从菜单中选择一行时,ZUUIRevealController 库都会创建视图控制器的新实例。所以我在 .h 文件中创建了视图控制器的实例变量,但我仍然有同样的问题。

这是我的代码

// AppDelegate.m // 在 SplashViewController 上,我决定是显示菜单还是登录屏幕

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.splashViewController = [[SplashViewController alloc]initWithNibName:@"SplashViewController" bundle:nil];
    self.window.rootViewController = self.splashViewController;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self customizeUIControlsAppearance];
    return YES;
}

// SplashViewController.m

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    BOOL isLoggedIn = YES;
    if(isLoggedIn){
        [self showMenuViewController];
    }
    else{
        [self showStartUpViewController];
    }
}

-(void)showStartUpViewController
{
    StartUpViewController *startUpViewController = [[StartUpViewController alloc]initWithNibName:@"StartUpViewController" bundle:nil];
    UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:startUpViewController];
    [self presentViewController:navController animated:NO completion:^{

    }];
}

-(void)showMenuViewController
{
    MenuViewController *menuViewController=[[MenuViewController alloc] init];
    CategoryViewController *categoryViewController=[[CategoryViewController alloc]initWithNibName:@"CategoryViewController" bundle:nil];
    categoryViewController.isViewControllerShownFromMenu = YES;
    UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:categoryViewController];
    RevealController *revealController=[[RevealController alloc] initWithFrontViewController:navController rearViewController:menuViewController];
    [self presentViewController:revealController animated:NO completion:^{

    }];
}

// 菜单视图控制器.m

// SettingsViewController 和 NewsViewController 在 .h 文件中带有属性和合成器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    RevealController *revealController = [self.parentViewController isKindOfClass:[RevealController class]] ? (RevealController *)self.parentViewController : nil;

    // Switch using Section Number
    switch (indexPath.section) {
        case OTHER_SECTION:
            switch (indexPath.row) {
                case NEWS:
                    [self showNewsViewControllerUsingRevealController:revealController];
                    break;
                case SETTINGS:
                    [self showSettingsViewControllerUsingRevealController:revealController];
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }

}

#pragma mark - Show News & Settings View Controllers

-(void)showNewsViewControllerUsingRevealController:(RevealController*)revealController
{
    if ([revealController.frontViewController isKindOfClass:[UINavigationController class]] && ![((UINavigationController *)revealController.frontViewController).topViewController isKindOfClass:[NewsViewController class]])
    {
        if(!self.newsViewController)
            self.newsViewController = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
        self.newsViewController.isViewControllerShownFromMenu = YES;
        UINavigationController *navigationController= [[UINavigationController alloc] initWithRootViewController:self.newsViewController];

        [revealController setFrontViewController:navigationController animated:NO];
    }
    else
    {
        [revealController revealToggle:self];
    }
}

-(void)showSettingsViewControllerUsingRevealController:(RevealController*)revealController
{
    if ([revealController.frontViewController isKindOfClass:[UINavigationController class]] && ![((UINavigationController *)revealController.frontViewController).topViewController isKindOfClass:[SettingsViewController class]])
    {
        if(!self.settingsViewController)
            self.settingsViewController= [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
        self.settingsViewController.isViewControllerShownFromMenu = YES;
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.settingsViewController];

        [revealController setFrontViewController:navigationController animated:NO];
    }
    else
    {
        [revealController revealToggle:self];
    }
}

// 显示 UIAlertView 和 UIActionsheet 的代码

-(void)showAlertWithTitle:(NSString*)title andMessage:(NSString*)message
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
}

-(void)btnInviteTapped:(id)sender event:(UIEvent*)event
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:NSLocalizedString(@"FRIENDS_VC:INVIT_ACTIONSHEET_TITLE", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"FRIENDS_VC:ACTIONSHEET_CANCEL_BUTTON",nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"FRIENDS_VC:ACTIONSHEET_SMS_BUTTON",nil),NSLocalizedString(@"FRIENDS_VC:ACTIONSHEET_EMAIL_BUTTON",nil), nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view];
}

顺便说一下,我有11 个菜单项

我的登录和注册流程未嵌入在 MenuViewController 中。在 Login & REgsiter , UIAlertView & UIActionSheet 显示顺利。

知道这里出了什么问题吗?我在编码中犯了一些错误吗?为什么我的 UIAlertView 和 UIActionsheet 显示不流畅?任何形式的帮助表示赞赏。谢谢。

4

0 回答 0