Daljeet
Daljeet

Reputation: 1595

AMSlideMenu Cell click takes time to open another view?

I’m building an article reading app.I’m using AMSliderMenu(https://github.com/SocialObjects-Software/AMSlideMenu) library for menu list.
When i click on any cell in AMSlideMenu it load into another table view which contain list of articles. I’m fetching article data in uitableview with JSON.
The issue is when i click on list of menu in AMSlideMenu it takes time to open another view.How can i resolve this problem.

Here is my code:

        - (void)viewDidLoad
            {
             [super viewDidLoad];
             BOOL myBool = [self isNetworkAvailable];
             if (myBool)
                {
                 @try {

                   _Title1 = [[NSMutableArray alloc] init];
                   _Author1 = [[NSMutableArray alloc] init];
                  _Images1 = [[NSMutableArray alloc] init];
                 NSData* data = [NSData dataWithContentsOfURL:ysURL];
            NSArray *ys_avatars = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

               if(ys_avatars){
                for (int j=0;j<ys_avatars.count;j++)
                 {
                    [_Title1 addObject:ys_avatars[j][@"title"]];
                    [_Author1 addObject: ys_avatars[j][@"author"]];
                     [_Images1 addObject: ys_avatars[j][@"featured_img"]];
    }

           }

        else

        {

            NSLog(@"asd");

          }

      }

    @catch (NSException *exception) {

     }

    [self LoadMore];

    [self LoadMore];
           });

          });

       }

       }

          -(void)LoadMore
         {     BOOL myBool = [self isNetworkAvailable];
      if (myBool)
        {

     @try {

           // for table cell seperator line color

         self.tableView.separatorColor = [UIColor colorWithRed:190/255.0 green:190/255.0 blue:190/255.0 alpha:1.0];

         // for displaying the previous screen lable with back button in details view controller

         UIBarButtonItem *backbutton1 = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
         [[self navigationItem] setBackBarButtonItem:backbutton1];
         NSString *urlString=[NSString stringWithFormat:@"www.example.com&page=%d",x];                             NSURL *newUrl=[NSURL URLWithString:urlString];
               NSData* data = [NSData dataWithContentsOfURL:newUrl];
             NSArray *ys_avatars = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
           x++;
         if(ys_avatars){                 
           for (int j=0;j<_Title1.count ;j++)
              {
               [_Title1 addObject:ys_avatars[j][@"title"]];
                 [_Author1 addObject: ys_avatars[j][@"author"]]; 
                [_Images1 addObject: ys_avatars[j][@"featured_img"]];

           }             }
           else
              { NSLog(@"asd");       }
              [self.tableView reloadData];}
             @catch (NSException *exception) {
          }} }

        - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

           {
              return 1;
                }
        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
       {
        return _Title1.count;
             }

Upvotes: 0

Views: 209

Answers (1)

arturdev
arturdev

Reputation: 11039

Its because you have done many many works in viewDidLoad method that's executing synchronously, and that view controller will not be shown until the code in viewDidLoad will not executed completely. So, load your data asynchronously or do it in viewDidAppear method, but I strongly suggest you to do it asynchronously.

Upvotes: 0

Related Questions