0

我有很多视图控制器,当我单击 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];
}

有什么办法可以让视图快速加载

4

1 回答 1

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];
于 2013-07-08T06:40:08.607 回答