如何在 ipad 应用程序中快速移动到新视图
Posted
技术标签:
【中文标题】如何在 ipad 应用程序中快速移动到新视图【英文标题】:how to move to the new view fast in ipad application 【发布时间】:2013-07-08 06:27:24 【问题描述】:当我单击 tableView 单元格时,我有很多视图控制器,它移动到新的视图控制器问题是移动到下一个视图需要很长时间可能是由于要加载从服务器获取数据的视图这是我的加载视图的代码
- (void)viewDidLoad
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
UIImageView *bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Nav.png"]];
[bottomImageView setFrame:CGRectMake(0,690,1024,34)];
[self.view addSubview:bottomImageView];
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0, 2.0, 88, 40.0)];
[button1 addTarget:self action:@selector(loginPressed) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imageNamed:@"logoutN.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.rightBarButtonItem = button;
self.title=@"Catalog";
popImageView.hidden=YES;
passwordLabel.hidden=YES;
userLabel.hidden=YES;
userNameTextField.hidden=YES;
userPasswordTextField.hidden=YES;
signInButton.hidden=YES;
tableView.hidden=NO;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
if(!categoryArray)
categoryArray =[[NSMutableArray alloc] init];
if(!userArray)
userArray =[[NSMutableArray alloc] init];
if(!subCategoryArray)
subCategoryArray =[[NSMutableArray alloc] init];
if(!subCategoryArrayOne)
subCategoryArrayOne =[[NSMutableArray alloc] init];
if(!subCategoryArrayTwo)
subCategoryArrayTwo =[[NSMutableArray alloc] init];
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
int count=[appDelegate.coffeeArray count];
NSLog(@"Arrays Content Are %d",count);
tableView.backgroundView = nil;
[super viewDidLoad];
有什么办法可以让视图快速加载
【问题讨论】:
延迟与图像加载或数据设置有关?简介以找出答案。然后决定是否可以在后台运行耗时的代码。 【参考方案1】:您的视图加载速度不快,因为我猜想 viewDidLoad 方法中的那些数据集操作。我认为这些是:
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
您可以做的一件事是将这些操作移到后台线程上执行。为此,将此操作移至单独的函数并调用该函数以在视图的后台执行加载方法:
-(void)dataOperations
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
并在 viewDidLoad 中在后台调用此函数:
[self performSelectorInBackground:@selector(dataOperations) withObject:nil];
或者您可以直接从 viewDidLoad 调用这些方法,例如:
[self performSelectorInBackground:@selector(setUpData) withObject:nil];
【讨论】:
以上是关于如何在 ipad 应用程序中快速移动到新视图的主要内容,如果未能解决你的问题,请参考以下文章