UIPickerViewを使用して「スロットマシン」ゲームを構築しようとしています。UIImageViewを使用してデータを入力します。問題は、ピッカービューのランダムな画像がスピンするたびに消え、ランダムに再び表示されることです。これは、ios 5.1.1を搭載したデバイスで発生しますが、ios4.2.1とシミュレーターを搭載したデバイスでは完全に機能します。現在、CircularPickerViewを使用していますが、UIPickerViewを使用する前は、問題は同じでした。スクリーンショットは次のとおりです:http://axgrzesiek.w.interii.pl/licznik.PNG
GraViewController.h:
#import <UIKit/UIKit.h>
#import "CircularPickerView.h"
@interface GraViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
CircularPickerView *picker;
UILabel *winLabel;
NSArray *column1;
NSArray *column2;
NSArray *column3;
}
@property(nonatomic, retain) IBOutlet CircularPickerView *picker;
@property(nonatomic, retain) IBOutlet UILabel *winLabel;
@property(nonatomic, retain) NSArray *column1;
@property(nonatomic, retain) NSArray *column2;
@property(nonatomic, retain) NSArray *column3;
-(IBAction)spin;
@end
GraViewController.m:
- (IBAction)spin {
BOOL win = NO;
int numInRow = 1;
int lastVal = -1;
for (int i = 0; i < 3; i++) {
int newValue = arc4random() % [self.column1 count];
if (newValue == lastVal)
numInRow++;
else
numInRow = 1;
lastVal = newValue;
//if (newValue < [self.column1 count] || newValue >= (2 * [self.column1 count]) ) {
//newValue = newValue % [self.column1 count];
//newValue += [self.column1 count];
[self.picker selectRow:newValue inComponent:i animated:YES];
//}
NSLog(@"kol:%d %d",i, newValue);
//[picker reloadComponent:i];
if (numInRow >= 3)
win = YES;
}
if (win)
winLabel.text = @"WIN!";
else
winLabel.text = @"";
//[picker reloadAllComponents];
//[self performSelector:@selector(moveIntoPosition) withObject:nil afterDelay:0.5f];
- (void)viewDidLoad {
NSString *title=@"Gra";
[self setTitle:title];
UIImage *seven = [UIImage imageNamed:@"jeden.png"];
UIImage *bar = [UIImage imageNamed:@"dwa.png"];
UIImage *crown = [UIImage imageNamed:@"trzy.png"];
UIImage *cherry = [UIImage imageNamed:@"cztery.png"];
UIImage *lemon = [UIImage imageNamed:@"piec.png"];
UIImage *apple = [UIImage imageNamed:@"szesc.png"];
for (int i = 1; i <= 3; 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];
//column1=[[NSArray alloc]initWithArray:imageViewArray];
//column2=[[NSArray alloc]initWithArray:imageViewArray];
//column3=[[NSArray alloc]initWithArray:imageViewArray];
[fieldName release];
[imageViewArray release];
[sevenView release];
[barView release];
[crownView release];
[cherryView release];
[lemonView release];
[appleView release];
//[picker selectRow: [self.column1 count] * (48 / 2) inComponent:i-1 animated:NO];
}
}
- (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];
[arrayName release];
return [array objectAtIndex:row];
}