如何在ipad应用程序中快速移动到新视图

时间:2013-07-08 06:27:25

标签: ios ipad uiviewcontroller

我有很多视图控制器当我点击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 个答案:

答案 0 :(得分:0)

您的视图加载速度不快,因为我猜这些数据集操作在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];