我开始使用新的iOS应用程序,我必须使用Reveal控件。所以我打算使用很棒的ZUUIRevealController库。我刚创建了2到3个屏幕的UI。在其中一个屏幕中,我必须展示UIAlertView& UIActionsheet。但我意识到 UIAlertView& UIActionsheet显示非常缓慢(它首先添加黑色叠加,然后显示UIAlertView / UIActionsheet,显示时会出现一种警报视图。动画不顺畅)。我没有为刚刚创建的UI添加任何编码逻辑。我没有使用任何后台线程/ dispatch_asyn()。因此,没有从后台线程更新UI的问题。所以我检查了内存泄漏和分配。我没有看到任何内存泄漏,但内存分配继续增加,而我显示菜单&推新视图控制器。当我弹出视图控制器时它不会减少。以下是截图:
1)当应用程序启动时
2)一段时间后,当我按下新视图控制器时,弹出视图控制器
我知道ZUUIRevealController库每次从Menu中选择一行时都会创建一个新的视图控制器实例。所以我在.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:^{
}];
}
// MenuViewController.m
// SettingsViewController& NewsViewController在.h文件中使用属性& syntheszie
- (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个菜单项。
我的登录& Regsiter流未嵌入MenuViewController中。在登录& REgsiter,UIAlertView& UIActionSheet顺利显示。
有什么想法在这里出错吗?我在编码时犯了一些错误吗? 为什么我的UIAlertView& UIActionsheet没有顺利显示? 任何形式的帮助表示赞赏。感谢。