Reputation: 83
I have implemented a UITableView
programmatically and it works fine but the only problem is that once i run the application, it just shows a white window and then after about 5 - 10 seconds, it displays the tableView. Is there a way to make it display the tableView faster?
This is what I have so far:
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
_accountNumbers = [account accountsWithAccountType:accountType];
if ([_accountNumbers count] > 1) {
//create a nagigation bar
//create a table view
self.tableView = [self createTableView];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.view addSubview: self.tableView];
}
- (UITableView *) createTableView {
CGFloat x = 0;
CGFloat y = 50;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
CGRect tableFrame = CGRectMake(x, y, width, height);
UITableView *tableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
tableView.rowHeight = 45;
tableView.sectionFooterHeight = 22;
tableView.sectionHeaderHeight = 22;
tableView.scrollEnabled = YES;
tableView.showsVerticalScrollIndicator = YES;
tableView.userInteractionEnabled = YES;
tableView.bounces = YES;
tableView.delegate = self;
tableView.dataSource = self;
return tableView;
}
Is there a reason why it delays the tableView from being shown?
Upvotes: 0
Views: 88
Reputation: 66244
From the ACAccountStore Class Reference on requestAccessToAccountsWithType:options:completion:
:
The handler is called on an arbitrary queue.
However, the "Threading Considerations" section of the UIView Class Reference says:
Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. The only time this may not be strictly necessary is when creating the view object itself but all other manipulations should occur on the main thread.
Therefore, change your code to this:
if ([_accountNumbers count] > 1) {
dispatch_sync(dispatch_get_main_queue(), ^{
//create a table view
self.tableView = [self createTableView];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.view addSubview: self.tableView];
});
}
Upvotes: 1
Reputation: 1142
It seems that you're using a twitter account as your data source. Are you making network requests that take some time to complete, then displaying the results in the table? Your code doesn't show when the requests are made, or how cells are counted or created.
Upvotes: 0