Mobile conf
Upcoming SlideShare
Loading in...5
×
 

Mobile conf

on

  • 311 views

 

Statistics

Views

Total Views
311
Views on SlideShare
291
Embed Views
20

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 20

http://www.linkedin.com 18
https://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mobile conf Mobile conf Presentation Transcript

  • UITableView 1 @dchohfi
  • Diego Chohfi Turini Instutor na Caelum Desenvolvedor na MakeYou@dchohfi 2 @dchohfi
  • EpicLyrics BusaoSP 3 @dchohfi
  • UITableViewUITableViewStylePlain UITableViewStyleGrouped 4 @dchohfi
  • UITableView UITableViewStylePlain muito rápidoUIScrollView customizável 5 @dchohfi
  • section }NSIndexPath} rows }NSIndexPath section} rows 6 @dchohfi
  • Header (UIView) UITableViewCellTudo é classe! Lembre-seque é orientado a objetos!7 @dchohfi
  • NSIndexPath informaçãoUITableViewCellinitWithStyle:reuseIdentifier:UITableViewCellStyle 8 @dchohfi
  • UITableView <UITableViewDataSource>@interface DCViewController : UIViewController <UITableViewDataSource> self.tableView.dataSource = self; 9 @dchohfi
  • - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 10 @dchohfi
  • 100 linhas = 100 UITableViewCellUITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 11 @dchohfi
  • dequeueReusableCellWithIdentifier:UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];if(!cell){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];} 12 @dchohfi
  • Ok, mas como sair disso: 13 @dchohfi
  • Pra isso: 14 @dchohfi
  • 15 @dchohfi
  • Primeiro de tudo: precisamos aprender a customizar uma célula @interface DCCustomCell : UITableViewCell @end 16 @dchohfi
  • Podemos até criar um XIB pra ela :D desenhamos a tela temos que LEMBRAR do identifier alteramos a classe ta interfaceprincipal para a nossa customizadae para acessar os elementos visuais, criamos IBOutlet 17 @dchohfi
  • e a API evoluiu bastante :D iOS > 5- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier rigistramos o novo xib na tabela UINib *customNib = [UINib nibWithNibName:@"DCCustomCell" bundle:[NSBundle mainBundle]]; [self.tableView registerNib:customNib forCellReuseIdentifier:@"DCCustomCell"]; e podemos remover um if! o/- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ DCCustomCell *cell = (DCCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"DCCustomCell"]; 18 @dchohfi
  • 19 @dchohfi
  • Agora precisamos melhorar a performance. Primeira regra: NUNCA FAÇA DOWNLOAD SÍNCRONONSURL *avatarURL = [NSURL URLWithString:user[@"profile_image_url"]];self.avatar.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:avatarURL]];a cada download da imagem, tudo trava, inclusive seu usuário.. 20 @dchohfi
  • open source FTW! 21 @dchohfi
  • SDWebImage 22 @dchohfi
  • Muito simples![self.avatar setImageWithURL:[NSURL URLWithString:user[@"profile_image_url"]]]; 23 @dchohfi
  • Mas, ainda temos problema de performance cada subview é desenhada separadamente e agora? temos que desenhar tudo de uma vez! sem xib :( 24 @dchohfi
  • Podemos desenhar todos os conteúdos estáticos de uma vez só! - (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width NSString withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode; UIImage - (void)drawInRect:(CGRect)rect; quando a célula for desenhada - (void)drawRect:(CGRect)rect; 25 @dchohfi
  • Porém sempre que o conteúdo da célula mudar, precisamos mandar ela se redesenhar. setNeedsDisplay- (void) setTweetData: (NSDictionary *) tweet { self.twitterData = tweet; NSURL *userAvatarUrl = [NSURL URLWithString:self.twitterData[@"user"][@"profile_image_url"]]; [self.avatar setImageWithURL:userAvatarUrl]; [self setNeedsDisplay];} 26 @dchohfi
  • 27 @dchohfi
  • E quando queremos celulas com alturas variaveis?podemos saber o tamanho de um texto, com uma fonte, de maneira simples: - (CGSize)sizeWithFont:(UIFont *)font NSString constrainedToSize:(CGSize)size;agora nós temos o controle :D - (CGFloat) tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath 28 @dchohfi
  • Cuidados que precisamos tomarreutilizar as celulas sempre que possível evitar desenhar todas as subviews, drawRect: FTW! evitar sombras e bordas arredondas evitar desenhar elementos com coordenadas quebradas deixar tudo calculado antes 29 @dchohfi
  • CUIDADO MANO! 30 @dchohfi
  • 10% de desconto nos livros da Cupom: MOBILECONF no site10% de desconto nos cursos da Caelum também o/ 31 @dchohfi
  • valeu galera :D 32 @dchohfi