(Réglé) Sérialisation très longue

Ben77650Ben77650 Membre
juillet 2014 modifié dans API UIKit #1

Bonjour à  tous,

 

Dans un souci d'optimiser mon appli, je cherche à  ce qu'elle soit fluide.

 

Et il s'avère que la page ou j'affiche des objets sérialisés met au moins 5 secondes à  s'afficher, ce qui vous en conviendrez, est très long.

 

Voila ce que je fais:



SerializableRepository* ser = [[SerializableRepository alloc]init];
    if([[ser getAll]count] > 0)
    {
        _liste = [ser getAll];
    }


-(NSMutableArray*) getAll
{
    for(int i=0;i<[objects count];i++){
        [objects objectAtIndex:i];
    }
    return objects;
}

Ma liste est composée de 16 éléments (14 NSString, 1 BOOL and 1 NSArray).


 


Pouvez-vous m'aider à  optimiser cela, s'il vous plait ?


 


Merci d'avance


Mots clés:
«1

Réponses

  • Tu sembles avoir zappé des lignes dans ce que tu sembles faire.

    C'est le getAll qui ralentit ? Car tu le fais 2 fois (dans le test if, et ensuite). Que tu dit Instruments ?


    Y'a plusieurs trucs qui semblent absent. objects? J'capte pas ta boucle for.



  • @interface SerializableRepository : NSObject
    {
        NSMutableArray* objects;
        NSString* fichier;
    }

    -(NSMutableArray*) getAll;
    - (void) save:(NSMutableArray*) objets;
    - (void) remove:(NSMutableArray*) objets;


    @implementation SerializableRepository

    -(id)init{
        self = [super init];
        if(self)
        {
            objects = [NSMutableArray new];
             NSString* documentPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
             fichier = [documentPath stringByAppendingPathComponent:@objets.archive];
             id serializeObjet = [NSKeyedUnarchiver unarchiveObjectWithFile:fichier];
             if(serializeObjet==nil){
             objects = [NSMutableArray new];
             }
             else{
             objects = serializeObjet;
             }

        }
        return self;
    }

    -(void) save:(NSMutableArray*) tab
    {
        [objects addObject:tab];
        [NSKeyedArchiver archiveRootObject:objects toFile:fichier];
        
    }
    -(void) remove:(NSMutableArray*) tab;
    {
        int indexTab = 0;
        if([objects count]>0 && [tab count]>0)
        {
            NSSet* set1=[NSSet setWithArray:tab];
            
            for(int i=0;i<[objects count];i++)
            {
                NSSet* set2=[NSSet setWithArray:[objects objectAtIndex:i]];
                if([set1 isEqualToSet:set2])
                {
                    indexTab = i;
                }
                
            }
            
            [objects removeObjectAtIndex:indexTab];
            [NSKeyedArchiver archiveRootObject:objects toFile:fichier];
        }
    }

    -(NSMutableArray*) getAll
    {
        for(int i=0;i<[objects count];i++){
            [objects objectAtIndex:i];
        }
        return objects;
    }


    @end

    Après je ne sais pas ce qui ralentis, si c'est le getAll :/


     


    Instruments, je l'ai pas utilisé, car je sais pas l'utiliser (j'avais essayé une fois sans succès)

  • Je n'ai toujours pas compris ce que faisait la boucle for dans getAll.


    Le init pourrait lui prendre du temps.


     


    Regarde ici, ils semblent expliquer comment utiliser TimeProfiler.


  • Ok je me suis chié sur le for qui sert à  rien, mais même sans ça, c'est presque aussi long.


     


    En quoi le init serait la cause ?


     


    Je regarde ton lien merci


  • Je joue rarement avec les fichiers, mais j'aurais tendance à  dire qu'en lire, et donc générer un accès disque pourrait prendre du temps.


  • Ok, si quelqu'un donc pouvais confirmer tes dires, ça sera cool


     


    Sinon je regarde ton lien, mais même en le lisant j'avoue toujours être perdu dans l'utilisation de l'outil...


  • Bon je sais pas si une capture de Elements peut vous aider mais dans le doute en voila une.


     


    Tout d'abord j'accède à  ma page principale, puis je fais une pause dans Instruments, puis par la suite j'accède à  ma page avec mes objets sérialisés


  • Ca ne vous aide pas le screenshot ? :/


  • Joanna CarterJoanna Carter Membre, Modérateur
    juillet 2014 modifié #10

    Moi, je fais le sérialisation dans "arrière-plan"



    - (void)updateStorage
    {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
    {
    NSString *appPreferencesPath = [self.storageURL URLByAppendingPathComponent:@preferences.plist].path;

    [NSKeyedArchiver archiveRootObject:self.preferences toFile:appPreferencesPath];
    });
    }


  • Bon j'ai testé ça, mais ça me fait planter l'application :/


     



    -(id)init{


        self = [super init];


        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{


        if(self)


        {


            objects = [NSMutableArray new];


             NSString* documentPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];


             fichier = [documentPath stringByAppendingPathComponent:@objets.archive];


             id serializeObjet = [NSKeyedUnarchiver unarchiveObjectWithFile:fichier];


             if(serializeObjet==nil){


             objects = [NSMutableArray new];


             }


             else{


             objects = serializeObjet;


             }


     


        }


        });


        return self;


    }


     


  • Joanna CarterJoanna Carter Membre, Modérateur


    Bon j'ai testé ça, mais ça me fait planter l'application :/




     


    Aaahhh ! Tu parles de sérialisation. C'est une autre chose.


     


    C'est quoi, ta problème ? Manque de vitesse visible ?

  • Ben77650Ben77650 Membre
    juillet 2014 modifié #13

    A l'heure actuelle la sérialisation fonctionne bien, mais le chargement de ma vue ou je récupère mes objets sérialisables est très long (presque 6-7 secondes)


     


    At actual time, serialisation goes well, but the loading of my uiview which use serialisable objects is very long (almost 6 or 7 seconds)


  • Joanna CarterJoanna Carter Membre, Modérateur
    juillet 2014 modifié #14


    A l'heure actuelle la sérialisation fonctionne bien, mais le chargement de ma vue ou je récupère mes objets sérialisables est très long (presque 6-7 secondes)


     


    At actual time, serialisation goes well, but the loading of my uiview which use serialisable objects is very long (almost 6 or 7 seconds)




     


    Et, c'est vraiment le désérialisation qui met le temps, ou, plutôt, le désérialisation des vues ?


     


    (Merci pour l'anglais mais je comprends le français mieux que je l'écrive ::)  )


  • A aucun moment je n'ai parlé de désérialisation (enfin je ne pense pas), ce qui est long à  afficher ce sont la liste de mes objets sérialisables (récupération faite par le getAll). Après je ne sais pas si c'est la vue en elle même qui est longue à  charger ou bien la récupération des objets (ou bien les 2)


  • Joanna CarterJoanna Carter Membre, Modérateur


    A aucun moment je n'ai parlé de désérialisation (enfin je ne pense pas), ce qui est long à  afficher ce sont la liste de mes objets sérialisables (récupération faite par le getAll). Après je ne sais pas si c'est la vue en elle même qui est longue à  charger ou bien la récupération des objets (ou bien les 2)




     


    Mais dans to code...



    self = [super init];
    if(self)
    {
    objects = [NSMutableArray new];
    NSString* documentPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    fichier = [documentPath stringByAppendingPathComponent:@objets.archive];
    id serializeObjet = [NSKeyedUnarchiver unarchiveObjectWithFile:fichier];
    if(serializeObjet==nil){
    objects = [NSMutableArray new];
    }
    else{
    objects = serializeObjet;
    }

    }
    return self;
    }


    ... tu as écrit [NSKeyedUnarchiver unarchiveObjectWithFile:fichier] - donc tu désérialise 


     


    Est-ce que tu as essayé d'afficher la vue sans le récupération des données ? ça passe plus vite ?

  • Si j'affiche la vue sans récupérer les données, oui c'est rapide, mais forcément vu qu'il n'y a absolument rien sur la vue, l'UITableView étant complètement vide, il y a simplement le menu en bas, une image en haut, la navigationController, et une UIView indiquant qu'il n'y a aucun favori



    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        SerializableRepository* ser = [[SerializableRepository alloc]init];
        if([[ser getAll]count] > 0)
        {
            _liste = [ser getAll];
        }
        
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(back)];
        
        listOffer.delegate=self;
        listOffer.dataSource=self;
        
        listOffer.editing=true;
        listOffer.allowsSelectionDuringEditing=true;
        
        if(_liste == nil)
        {
            loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 200, 170, 100)];
            loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            loadingView.clipsToBounds = YES;
            loadingView.layer.cornerRadius = 10.0;
            
            
            loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(32.5, 40, 140, 22)];
            loadingLabel.backgroundColor = [UIColor clearColor];
            loadingLabel.textColor = [UIColor whiteColor];
            loadingLabel.adjustsFontSizeToFitWidth = YES;
            loadingLabel.text = @Aucun favori.;
            loadingLabel.lineBreakMode = NSLineBreakByWordWrapping;
            loadingLabel.numberOfLines=0;
            loadingLabel.textAlignment = NSTextAlignmentCenter;
            [loadingLabel sizeToFit];
            [loadingView addSubview:loadingLabel];
            [self.view addSubview:loadingView];
        }
        
        UIView *theaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, listOffer.frame.size.width, 50)];
        theaderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
        imageView.image=[UIImage imageNamed:@logov2.jpg];
        [theaderView addSubview:imageView];
        listOffer.tableHeaderView = theaderView;
    }
  • Si c'est rapide quand tu ne récupère pas les objets le problème vient surement de là . Est ce que les objets sont lourd, nombreux ? 


  • Joanna CarterJoanna Carter Membre, Modérateur
    juillet 2014 modifié #19

    - (void)viewDidLoad
    {
    [super viewDidLoad];

    SerializableRepository* ser = [[SerializableRepository alloc]init];
    if([[ser getAll]count] > 0)
    {
    _liste = [ser getAll];
    }


    Tu as dit que la méthode [ser getAll] met du temps. Alors, c'est pourquoi tu l'appelles deux fois ?


     


    ça vaut mieux d'écrire...



    - (void)viewDidLoad
    {
    [super viewDidLoad];

    SerializableRepository* ser = [[SerializableRepository alloc]init];

    NSMutableArray *objets = [ser getAll];

    if(objets.count > 0)
    {
    _liste = objets;
    }

  • @Elton: Un objet est composée de 16 éléments (14 NSString, 1 BOOL and 1 NSArray). Et même si je n'ai qu'un seul objet sérialisable c'est long. Dans le cas de mon exemple j'en ai 3, et ça prends presque 7 secondes


     


    @Johanna, j'ai effectuée les modifications conseillées mais c'est toujours aussi long ;)


  • Joanna CarterJoanna Carter Membre, Modérateur
    juillet 2014 modifié #21
    De quoi se consistent les objets dans le NSArray ?
  • Le NSArray comprends 3 NSString et peut être un int (nom, valeur, unité et peut être l'id)


  • Mais ce tableau peut être vide, c'est un tableau d'options de mon annonce (ex: marque de voiture, taille de vetement, superficie d'une maison, etc.) et pour certains articles (high tech, objets de décoration, mobilier, etc.) il n'y a pas d'options


  • samirsamir Membre
    juillet 2014 modifié #24

    Tu fais forcément un truc tordu dans ton code qui te fait ralentir 7 secondes, ne n'est pas l'archivage de quelques chaines de caractère qui va te causer ça :). Si tu monterai plus de code comment tu archives et tu désactive tes objets et montre aussi sont structurer ces objets ( Article,...).



  • - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            self.title=@Mes favoris;
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@MonApplication accessGroup:nil];
        NSString *adEmail = [keychainItem objectForKey:(__bridge id)(kSecValueData)];
        
        MyManager *sharedManager = [MyManager sharedManager];
        if(sharedManager.userName !=nil || ![adEmail  isEqualToString:@""])
        {
            [_profil setTintColor:[UIColor whiteColor]];
        }
        else
        {
            [_profil setTintColor:[UIColor colorWithRed:51.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1]];
        }
        
        SerializableRepository* ser = [[SerializableRepository alloc]init];
        NSMutableArray *objets = [ser getAll];
        
        if(objets.count > 0)
        {
            _liste = objets;
        }
        
        _baseURL = @http://www.fr.monsite.com/images/photos/;
        limit=20;
        
        if(numpage ==0)
        {
            numpage=1;
        }
        
        [_etoile setTintColor:[UIColor colorWithRed:0.0/255.0 green:136.0/255.0 blue:204.0/255.0 alpha:1]];
        
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(back)];
        
        listOffer.delegate=self;
        listOffer.dataSource=self;
        
        listOffer.editing=true;
        listOffer.allowsSelectionDuringEditing=true;
        
        if(_liste == nil)
        {
            loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 200, 170, 100)];
            loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            loadingView.clipsToBounds = YES;
            loadingView.layer.cornerRadius = 10.0;
            
            
            loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(32.5, 40, 140, 22)];
            loadingLabel.backgroundColor = [UIColor clearColor];
            loadingLabel.textColor = [UIColor whiteColor];
            loadingLabel.adjustsFontSizeToFitWidth = YES;
            loadingLabel.text = @Aucun favori.;
            loadingLabel.lineBreakMode = NSLineBreakByWordWrapping;
            loadingLabel.numberOfLines=0;
            loadingLabel.textAlignment = NSTextAlignmentCenter;
            [loadingLabel sizeToFit];
            [loadingView addSubview:loadingLabel];
            [self.view addSubview:loadingView];
        }
        
        UIView *theaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, listOffer.frame.size.width, 50)];
        theaderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
        imageView.image=[UIImage imageNamed:@logov2.jpg];
        [theaderView addSubview:imageView];
        listOffer.tableHeaderView = theaderView;
    }

    - (void) reloadDateFromTable:(NSMutableArray*) reloadArray{
        _liste=reloadArray;
        [listOffer performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 100;
        
    }

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

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        DetailViewController* detail = [[DetailViewController alloc]init];
        detail.offreDetail=[_liste objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:detail animated:NO];
    }

    #define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

    static NSString* const UCellIdentifier = @CelluleOffre;
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        
        CelluleOffre* cell = (CelluleOffre *)[tableView dequeueReusableCellWithIdentifier:UCellIdentifier];
        if(cell==nil){
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:UCellIdentifier owner:nil options:nil];
            cell = [nib objectAtIndex:0];
        }
        
        id status =[[_liste objectAtIndex:indexPath.row] objectAtIndex:11];
        if([status  isEqual: @YES])
        {
            cell.imgStatus.image=[UIImage imageNamed:@online.png];
            cell.textStatus.text=@En ligne;
        }
        else if([status  isEqual: @NO])
        {
            cell.imgStatus.image=[UIImage imageNamed:@offline.png];
            cell.textStatus.text=@Hors ligne;
        }
        
        id urgent =[[_liste objectAtIndex:indexPath.row] objectAtIndex:12];
        if([urgent  isEqual: @YES])
        {
            cell.urgence.text=@URGENT;
            cell.logo_urg.image=[UIImage imageNamed:@urgent.jpg];
            cell.urgence.hidden=NO;
            cell.logo_urg.hidden=NO;
        }
        else if([urgent  isEqual: @NO])
        {
            cell.urgence.hidden=YES;
            cell.logo_urg.hidden=YES;
        }
        NSString* objet =[[_liste objectAtIndex:indexPath.row] objectAtIndex:0];
        objet = [objet stringByReplacingOccurrencesOfString:@&quot; withString:@\"];
        cell.labelObjet.text=objet;
        
        NSString* imgLink=[[_liste objectAtIndex:indexPath.row] objectAtIndex:1];
        NSString* lienImg = [NSString stringWithFormat:@%@%@", _baseURL,imgLink];
        NSURL* urlImg = [NSURL URLWithString:[lienImg stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        if([lienImg isEqual:_baseURL])
        {
            cell.imageOffre.image=[UIImage imageNamed:@no_photo.png];
        }
        else
        {
            /*[self downloadImageWithURL:urlImg completionBlock:^(BOOL succeeded, UIImage *imageOff) {
                cell.imageOffre.image=imageOff;
            }];*/
            cell.imageOffre.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:urlImg]];
        }
        
        NSString* date=[[_liste objectAtIndex:indexPath.row] objectAtIndex:2];
        date = [date stringByReplacingOccurrencesOfString:@- withString:@/];
        cell.labelDate.text=date;
        
        NSString* prix =[[_liste objectAtIndex:indexPath.row] objectAtIndex:3];
        NSString* euro = @€;
        NSString* prixeuro = [NSString stringWithFormat:@%@ %@", prix, euro];
        cell.labelPrix.text=prixeuro;
        
        
        NSString* city =[[_liste objectAtIndex:indexPath.row] objectAtIndex:4];
        NSString* ville=[[city componentsSeparatedByString:@,]objectAtIndex:0];
        cell.cityLabel.text=ville;
        
        
        cell.categLabel.text=[NSString stringWithString:[[_liste objectAtIndex:indexPath.row] objectAtIndex:5]];
        
        
        UIView *tfooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, listOffer.frame.size.width, 45)];
        tfooterView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        UILabel *labelPage = [[UILabel alloc] initWithFrame:CGRectMake(listOffer.frame.size.width/2-120, 0, 240, 35)];
        labelPage.backgroundColor = [UIColor clearColor];
        labelPage.font = [UIFont systemFontOfSize:12];
        labelPage.textAlignment = NSTextAlignmentCenter;
        
        NSString *numeroPage;
        
        numeroPage=[NSString stringWithFormat:@Page %d, numpage];
        
        labelPage.text = numeroPage;
        labelPage.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
        [tfooterView addSubview:labelPage];
        
        UIButton* prev = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 165, 40)];
        UIImage* prevImg = [UIImage imageNamed:@precedent.png];
        [prev setBackgroundImage:prevImg forState:UIControlStateNormal];
        [prev setTitle:@Précédent forState:UIControlStateNormal];
        [prev addTarget:self action:@selector(prevPage) forControlEvents:UIControlEventTouchUpInside];
        [tfooterView addSubview:prev];
        
        UIButton* next = [[UIButton alloc]initWithFrame:CGRectMake(150, 0, 165, 40)];
        UIImage* nextImg = [UIImage imageNamed:@suivant.png];
        [next setBackgroundImage:nextImg forState:UIControlStateNormal];
        [next setTitle:@Précédent forState:UIControlStateNormal];
        [next addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
        [tfooterView addSubview:next];
        
        listOffer.tableFooterView = tfooterView;
        
        
        return cell;
    }

    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
        if (indexPath.row == 0)
        {
            return NO;
        }
        return YES;
    }

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if(editingStyle == UITableViewCellEditingStyleDelete)
        {
            SerializableRepository* ser = [[SerializableRepository alloc]init];
            [ser remove:_liste];
            
            [_liste removeObjectAtIndex:indexPath.row];
            //[listOffer deleteRowsAtIndexPaths:@[;indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [listOffer reloadData];
            
            if([_liste count] == 0)
            {
                listOffer.tableFooterView.hidden = YES;
                
                loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 200, 170, 100)];
                loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
                loadingView.clipsToBounds = YES;
                loadingView.layer.cornerRadius = 10.0;
                
                
                loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(32.5, 40, 140, 22)];
                loadingLabel.backgroundColor = [UIColor clearColor];
                loadingLabel.textColor = [UIColor whiteColor];
                loadingLabel.adjustsFontSizeToFitWidth = YES;
                loadingLabel.text = @Aucun favori.;
                loadingLabel.lineBreakMode = NSLineBreakByWordWrapping;
                loadingLabel.numberOfLines=0;
                loadingLabel.textAlignment = NSTextAlignmentCenter;
                [loadingLabel sizeToFit];
                [loadingView addSubview:loadingLabel];
                [self.view addSubview:loadingView];
            }
        }
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
    }

    - (IBAction)home:(id)sender {
        HomeViewController* home = [[HomeViewController alloc]init];
        [self.navigationController pushViewController:home animated:NO];
    }

    - (IBAction)listeOffres:(id)sender {
        OffreViewController* offre = [[OffreViewController alloc]init];
        [self.navigationController pushViewController:offre animated:NO];
    }

    - (IBAction)nouvelleOffre:(id)sender {
        AjouterOffre* add = [[AjouterOffre alloc]init];
        [self.navigationController pushViewController:add animated:NO];
    }

    - (IBAction)listeFavoris:(id)sender {
        FavorisViewController* fav = [[FavorisViewController alloc]init];
        [self.navigationController pushViewController:fav animated:NO];
    }

    - (IBAction)accesProfil:(id)sender {
        Connexion* profil = [[Connexion alloc]init];
        [self.navigationController pushViewController:profil animated:NO];
    }

    -(void) back{
        HomeViewController* home = [[HomeViewController alloc]init];
        [self.navigationController pushViewController:home animated:NO];
    }

    -(void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self.navigationController setNavigationBarHidden:NO animated:NO];
    }

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        [self.navigationController setNavigationBarHidden:NO animated:NO];
    }

    - (void)nextPage{
        offset +=20;
        numpage++;
        
        
        NSIndexPath* index=[NSIndexPath indexPathForRow:0 inSection:0];
        [listOffer scrollToRowAtIndexPath:index atScrollPosition:(UITableViewScrollPosition)UITableViewRowAnimationTop animated:NO];
    }

    - (void)prevPage {
        if(numpage==1)
        {
            UIAlertView *erreur = [[UIAlertView alloc] initWithTitle:@Erreur
                                                             message:@Aucune page précédente
                                                            delegate:nil
                                                   cancelButtonTitle:@OK
                                                   otherButtonTitles:nil];
            [erreur show];
        }
        else
        {
            offset -=20;
            numpage--;
            
            NSIndexPath* index=[NSIndexPath indexPathForRow:0 inSection:0];
            [listOffer scrollToRowAtIndexPath:index atScrollPosition:(UITableViewScrollPosition)UITableViewRowAnimationTop animated:NO];
            
        }
    }
  • AliGatorAliGator Membre, Modérateur
    C'est Instruments qui va te dire exactement où ça coince, il est fait pour ça après tout.

    La tu nous as posté juste une capture de Instruments où tu n'as rien filtré et où tu n'as surtout rien déplié donc on ne voit même pas la méthode getAll, si c'est elle qui prend du temps, et si oui quelle ligne du code de getAll est si longue, donc on ne peut pas t'aider...
  • Après comme j'ai dit à  Larme, j'ai beau avoir lu son article, je ne comprends toujours pas comment ça fonctionne.


     


    Un peu d'aide personnalisée (à  la place d'un lien), ça ne serait pas de refus ;)


  • et si tu supprimes cette lignes cell.imageOffre.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:urlImg]];

  • AliGatorAliGator Membre, Modérateur
    Ouch oui j'avais pas vu cette ligne mais c'est clair celle là  elle fait très mal... du chargement synchrone (donc bloquante) d'une URL réseau, qu'elle idée...
  • Ok ça viens très certainement de la puisque sans ça, le chronomètre passe de 7 secondes à  2 secondes maximum ;)


  • Joanna CarterJoanna Carter Membre, Modérateur


    et si tu supprimes cette lignes cell.imageOffre.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:urlImg]];




     


    Bah wow ! ça mettrait beaucoup de temps

Connectez-vous ou Inscrivez-vous pour répondre.