2010-02-01 7 views
1

donc c'est fondamentalement comme une machine à sous, très basique, mais le problème que j'ai, c'est que lorsque vous cliquez sur le bouton tourner le mouvement des composants n'est pas animé, même si j'ai envoyé un OUI BOOL. Je n'ai aucune idée de ce que je fais de mal, toute aide serait appréciée.Pourquoi mon UIPickerView ne s'anime pas comme il se doit?

Nick

télécharger ps l'ensemble du projet ici: http://files.me.com/knyck2/dcca9y

// 
     // CustomPickerViewController.m 
    // Pickers 
    // 
    // Created by Nicholas Iannone on 1/29/10. 
    // Copyright 2010 Apple Inc. All rights reserved. 
    // 

    #import "CustomPickerViewController.h" 


    @implementation CustomPickerViewController 

    @synthesize column1, column2, column3, column4, column5, picker, winLabel; 

    -(IBAction) spin : (id) sender { 

NSLog(@"even got here"); 

BOOL win = NO; 

int numInRow = 1; 

int lastVal = -1; 

for (int i = 0; 1 < 5; i++) { 
int newValue = random() % [self.column1 count]; 

if (newValue == lastVal) { 
    NSLog(@"even got here"); 

numInRow++; 
} 
else 
    numInRow = 1; 

    lastVal = newValue; 
[picker selectRow:newValue inComponent:i animated:YES]; 
[picker reloadComponent:i]; 
if (numInRow >= 3) 
    win = YES; 

NSLog(@"even got here"); 

} 

if (win) 
winLabel.text = @"winner!"; 

      else { 
winLabel.text = @""; 
      NSLog(@"even got here"); 
      } 

    } 

    /* 
    // The designated initializer. Override if you create the controller  programmatically    and want to perform customization that is not appropriate  for viewDidLoad. 
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
// Custom initialization 
} 
return self; 
    } 
    */ 


    // Implement viewDidLoad to do additional setup after loading the view, typically from   a nib. 
    - (void)viewDidLoad { 
UIImage *seven = [UIImage imageNamed:@"seven.png"]; 
UIImage *bar = [UIImage imageNamed:@"bar.png"]; 
UIImage *crown = [UIImage imageNamed:@"crown.png"]; 
UIImage *cherry = [UIImage imageNamed:@"cherry.png"]; 
UIImage *lemon = [UIImage imageNamed:@"lemon.png"]; 
UIImage *apple = [UIImage imageNamed:@"apple.png"]; 

for (int i = 1; i <= 5 ; i++) { 
    UIImageView *sevenView = [[UIImageView alloc] initWithImage: seven]; 
    UIImageView *barView = [[UIImageView alloc] initWithImage: bar]; 
    UIImageView *crownView = [[UIImageView alloc] initWithImage: crown]; 
    UIImageView *cherryView = [[UIImageView alloc] initWithImage:  cherry]; 
    UIImageView *lemonView = [[UIImageView alloc] initWithImage: lemon]; 
    UIImageView *appleView = [[UIImageView alloc] initWithImage: apple]; 


    NSArray *imageViewArray = [[NSArray alloc] initWithObjects:  sevenView, barView, crownView, cherryView, lemonView, appleView, nil]; 
    NSString *fieldName =[[NSString alloc] initWithFormat:@"column%d",  i]; 
    [self setValue:imageViewArray forKey:fieldName]; 
    [fieldName release]; 
    [imageViewArray release]; 

    [sevenView release]; 
    [crownView release]; 
    [barView release]; 
    [cherryView release]; 
    [lemonView release]; 
    [appleView release]; 

    } 

srandom(time(NULL)); 
[super viewDidLoad]; 
    } 



    /* 
    // Override to allow orientations other than the default portrait orientation. 
    -  (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
    */ 

    - (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
    } 

    - (void)viewDidUnload { 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
    } 


    - (void)dealloc { 
[picker release]; 
[winLabel release]; 
[column1 release]; 
[column2 release]; 
[column3 release]; 
[column4 release]; 
[column5 release]; 


[super dealloc]; 
    } 


    #pragma mark - 
    #pragma mark Picker Data Source Methods 

    -(NSInteger) numberOfComponentsInPickerView: (UIPickerView *) pickerView { 

return 5; 
    } 


    -(NSInteger) pickerView: (UIPickerView *) pickerView numberOfRowsInComponent:   (NSInteger) component { 

return [self.column1 count]; 

    } 

    #pragma mark Picker Delegate Methods 

    -(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger) component reusingView : (UIView *)view { 

NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d", component + 1]; 
NSArray *array = [self valueForKey:arrayName]; 
NSLog(@"got here yo"); 
return [array objectAtIndex: row]; 
NSLog(@"holyshit"); 


    } 

    @end 
+0

désolé le premier lien vers le projet était une ancienne version qui n'a pas fonctionné, le nouveau lien là-bas. – nickthedude

Répondre

1

Je suis retourné et comparé mon code au livre dans lequel ce projet est listé et j'ai remarqué que mon code fonctionnerait comme prévu (avec animation) si je devais construire en 3.1.2 sdk et iphone sim. Donc quelque chose dans le nouveau xcode est en train d'écraser l'animation, du moins c'est comme ça que ça apparaît.

+0

J'ai le même problème. Soit dans iOS4 + ou iOS5 +, l'animation programmatique de l'UIPickerView a été modifiée pour être très abrupte, pas lisse comme la décélération en douceur que vous obtenez lorsque vous feuilletez manuellement UIPickerView. Des suggestions quelqu'un? – Bogatyr

0

Il est probablement pas animant parce que vous faites [picker reloadComponent:i] juste après avoir sélectionné une ligne avec animation. Le rechargement provoque probablement l'arrêt de toute animation et ne devrait pas être nécessaire puisque vous ne modifiez pas réellement le contenu du sélecteur.

+0

je me suis débarrassé de lui et toujours la même chose, d'autres idées? est-ce que c'est peut-être quelque chose dans la plume? – nickthedude

Questions connexes