1 din 2
1
Download image from web
  [ Ignoră ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

Intr-un UITableView , in fiecare cell , trebuie sa aduc 5 poze care se gasesc la o adresa web ( rcaleImagineProdus in codul de mai jos ).
Pentru a nu fi nevoit sa astepti , folosesc performSelectorInBackground astfel :

.
.
ProdusCustomCell *cell [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (
cell == nil{
        cell 
[[ProdusCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
    
}

.
.
[self performSelectorInBackground:@selector(updateImageView:) withObject:cell.stingaPozaImageView ];
[self performSelectorInBackground:@selector(updateImageView:) withObject:cell.centruStingaPozaImageView ];
[self performSelectorInBackground:@selector(updateImageView:) withObject:cell.centruPozaImageView ];
[self performSelectorInBackground:@selector(updateImageView:) withObject:cell.centruDreaptaPozaImageView ];
[self performSelectorInBackground:@selector(updateImageView:) withObject:cell.dreaptaPozaImageView ];.
.


- (
void)updateImageView:(UIImageView *)imgDownload
{
     ImageCache 
*imagine [[ImageCache alloc] init];
     
imgDownload.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:imgDownload.accessibilityValue] imageName:imgDownload.accessibilityValue deleteImage:NO];
     
[(UIActivityIndicatorView *)[imgDownload.superview viewWithTag:[imgDownload tag]+40] stopAnimating];
  

Daca esti suficient de iute , sau ai o conexiune slaba , dupa ce faci scroll , in loc sa iti apara poza aferenta randului existent pe ecran (adica poza din pozitia numarRand*5+pozitieInCell ), pozele sunt afisate una dupa alta , in final afisind imaginea dorita .

Intrebarea este : cum ma sfatuiti sa “marchez” obiectul astfel incit sa nu mai apara succesiunea de imagini ? Orice alte sugestii sunt binevenite .

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 1 ]
Avatar
RankRankRankRank
Administrator
Din: The Colony, TX
Macuser din: 11.10.05

Io nu ma pricep la programarea in ObjectiveC, dar cum ar fi sa incarci in prealabil in locul respectiv o imagine locala - o imagine complet alba sau un checkerboard de ala si dupa aia sa incarci pozele deasupra.

 Semnătură 

Apple:5x macmini (G4, 2007, 2009, 2010, 2012)
UNIX:IBM 7011-250/AIX 5.1, HP Jornada 680/JLime, HP 9000 F20/HP-UX 11.11
PC:PentiumD/Debian, HP t5300/Debian
Misc:Spectrum 48k, 8x Raspberry Pi, 2x CHIP

Profil
 
  [ Ignoră ]   [ # 2 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

inainte de a incarca imaginea , deasupra codului postat mai sus , pentru fiecare UiImageView setez image = nil .
cind ajung repede la randul n , se afisaza nil , imagen-3 , imagen-2 , imagen-1, image n

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 3 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

http://www.markj.net/iphone-asynchronous-table-image/

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 4 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

Multumesc .
Eu doresc sa evit “distrugerea” si “reinitializarea” obiectelor .

Pina la urma , daca nu gasesc alta solutie , o sa fac si asta .

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 5 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

am rezolvat utilizind

dispatch_queue_t dispatch_get_global_queue(
  long priority,
  unsigned long flags);

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 6 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

nu ai cum sa eviti reciclarea celulelor. pe baza asta e construit un TableView. ai putea sa faci un cache pe disk la imagini si sa le preiei de-acolo. ar fi o solutia viabila in opinia mea.

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 7 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

si apropo… felul in care asignezi imaginile aferente celulelor e “wrong on so many levels”.. pai tu trimiti pointer catre instanta celulei, cand tu stii ca celulele se refolosesc? practic tu intr-un tableView nu ai mai multe celule decat ai pe ecran din cauza ca se refolosesc. trebuie sa schimbi doar informatia din ele, pe care o iei din UITableViewDataSource delegate. datele alea se pasteaza in delegate, nu in interiorul celulei. hope I made myself clear! spor la codat!

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 8 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

pai nu am evitat reciclarea . am si cache ( vezi mai sus in updateImageView )
problema aparea atunci cind nu avem imaginile in cache .

Utilizarea GCD (Grand Central Dispatch ) rezolva problema utilizind reciclarea , si in opinia mea este o solutie foarte buna .

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 9 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

prefer sa evit GCDu cat mai mult, pentru ca pot aparea probleme de sync intre threaduri si e mult mai dificil de debug-uit! in majoritatea cazurilor performSelectorInBackground isi face treaba! apropo, vezi ca-ti lipseste NSAutoreleasePool-ul din updateImageView!

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 10 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

Threading is dead .
GCD asigura sincronizarea , garanteaza ordinea operatiilor , pune cozile de asteptare in grupuri si ai multiple cozi care asteapta simultan , daca vrei , poti sti cind o coada este goala, etc .Eu sunt mai mult decit incintat .
Am citit toata noaptea . Eu zic sa te mai gindesti si ai sa vezi ca este mult mai bine , si chiar mai usor , sa folosesti GCD .

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 11 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

cand ai de ingrijit 60k+ de linii de cod crede-ma ca fix GDC-ul iti lipseste! smile)

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 12 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

Daca il folosesti o sa ai mai putine linii de cod smile

“The key innovation of GCD is shifting the responsibility for managing threads and their execution from applications to the operating system.
As a result, programmers can write less code to deal with concurrent operations in their applications, and the system can perform more efficiently on single-processor machines,
large multiprocessor servers, and everything in between. ”

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 13 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

“KISS is an acronym for the design principle articulated by Kelly Johnson, Keep it simple, Stupid!.[1] Variations include “keep it short and simple”, “keep it simple sir”, “keep it simple or be stupid”, “keep it simple and stupid”, “keep it simple and straightforward” or “keep it simple and sincere.”[2] The KISS principle states that most systems work best if they are kept simple rather than made complex, therefore simplicity should be a key goal in design and unnecessary complexity should be avoided.”

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 14 ]
Avatar
RankRankRank
Member
Din: Ploiesti
Macuser din: 06.12.11

Problema pe care o aveam s-a rezolvat astfel :

.
.
ProdusCustomCell *cell [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (
cell == nil{
        cell 
[[ProdusCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
    
}
.
.
dispatch_queue_t queue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,  0);
ImageCache *imagine [[ImageCache alloc] init];
.
.
dispatch_async(queue, ^{
cell
.stingaPozaImageView.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:numeImagine] imageName:numeImagine deleteImage:NO];
cell.stingaCentruPozaImageView.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:numeImagine] imageName:numeImagine deleteImage:NO];
cell.centruImageView.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:numeImagine] imageName:numeImagine deleteImage:NO];
cell.dreaptaCentruPozaImageView.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:numeImagine] imageName:numeImagine deleteImage:NO];
cell.dreaptaPozaImageView.image [imagine getCachedImage:[rcaleImagineProdus stringByAppendingString:numeImagine] imageName:numeImagine deleteImage:NO];
});

.

Stabileste tu care este mai usor de intretinut , de gandit , de scris , si care corespunde principiului KISS .
Poti sa iei in calcul si exemplul din link-ul postat .

 Semnătură 


MacBook Pro 15”  i7 2.2GHz/ 16GB/ 500GB SSD ,  10.11
MacBook Air 13”  i5 1.3GHz/ 4GB/ 256GB SSD ,  10.11

Profil
 
  [ Ignoră ]   [ # 15 ]
Avatar
RankRank
Jr. Member
Din: Cluj
Macuser din: 10.03.09

Cred ca abordarea asta functioneaza pentru o lista relativ mica. Daca ai o lista de 100+ (sa zicem), si faci scroll usurel prin ea iar conexia nu este tocmai stralucita ai sa ai o gramada de download-uri inutile care nu vor face decat sa incetineasca si mai mult lucrurile. Daca-mi amintesc corect o abordare mai inteligenta era printr-un exemplu de la Apple unde se folosea NSOperationQueue, fiecare operatie avand un NSURLConnection (care bineinteles suporta cancel).

Profil
 
   
1 din 2
1