0
我試圖建立一個UIPicker視圖,其中包含所有的口袋妖怪的名稱和圖像。問題是,我似乎無法在同一行上獲取圖像和文本。什麼是最好的方法來做到這一點?NSArray的UIPickerView中的圖像和文本的NSArray
pokemonArray = @[@"Aerodactyl", @"Alakazam", @"Arbok", @"Arcanine", @"Articuna", @"Beedrill", @"Blastoise", @"Butterfree", @"Chansey", @"Charizard", @"Clefable", @"Cloyster", @"Dewgong", @"Ditto", @"Dodrio", @"Dragonite", @"Dugtrio", @"Electabuzz", @"Electrode", @"Exeggcutor", @"Farfetch'd", @"Fearow", @"Flareon", @"Gengar", @"Golbat", @"Golduck", @"Golem", @"Gyarados", @"Haunter", @"Hitmonchan", @"Hypno", @"Jolteon", @"Jynx", @"Kabutops", @"Kangaskhan", @"Kingler", @"Lapras", @"Lickitung", @"Machamp", @"Magmar", @"Magneton", @"Marowak", @"Mewtwo", @"Moltres", @"Mr Mime", @"Muk", @"Nidoking", @"Nidoqueen", @"Ninetales", @"Omastar", @"Onix", @"Parasect", @"Persian", @"Pidgeot", @"Pinsir", @"Poliwrath", @"Porygon", @"Primeape", @"Raichu", @"Rapidash", @"Raticate", @"Rhydon", @"Sandslash", @"Scyther", @"Seadra", @"Seaking", @"Slowbro", @"Snorlax", @"Starmie", @"Tangela", @"Tauros", @"Tentacruel", @"Vaporeon", @"Venomoth", @"Venusaur", @"Victreebel", @"Vileplume", @"Weezing", @"Wigglytuff", @"Zapdos"];
imageArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"Aerodactyl"],[UIImage imageNamed:@"Alakazam"],[UIImage imageNamed:@"Arbok"],[UIImage imageNamed:@"Arcanine"],[UIImage imageNamed:@"Articuna"],[UIImage imageNamed:@"Beedrill"],[UIImage imageNamed:@"Blastoise"],[UIImage imageNamed:@"Butterfree"],[UIImage imageNamed:@"Chansey"],[UIImage imageNamed:@"Charizard"],[UIImage imageNamed:@"Clefable"],[UIImage imageNamed:@"Cloyster"],[UIImage imageNamed:@"Dewgong"],[UIImage imageNamed:@"Ditto"],[UIImage imageNamed:@"Dodrio"],[UIImage imageNamed:@"Dragonite"],[UIImage imageNamed:@"Dugtrio"],[UIImage imageNamed:@"Electabuzz"],[UIImage imageNamed:@"Electrode"],[UIImage imageNamed:@"Electrode"],[UIImage imageNamed:@"Exeggcutor"],[UIImage imageNamed:@"Farfetch'd"],[UIImage imageNamed:@"Fearow"],[UIImage imageNamed:@"Flareon"],[UIImage imageNamed:@"Gengar"],[UIImage imageNamed:@"Golbat"],[UIImage imageNamed:@"Golduck"],[UIImage imageNamed:@"Golem"],[UIImage imageNamed:@"Gyarados"],[UIImage imageNamed:@"Haunter"],[UIImage imageNamed:@"Hitmonchan"],[UIImage imageNamed:@"Hypno"],[UIImage imageNamed:@"Jolteon"],[UIImage imageNamed:@"Jynx"],[UIImage imageNamed:@"Kabutops"],[UIImage imageNamed:@"Kangaskhan"],[UIImage imageNamed:@"Kingler"],[UIImage imageNamed:@"Lapras"],[UIImage imageNamed:@"Lickitung"],[UIImage imageNamed:@"Machamp"],[UIImage imageNamed:@"Magmar"],[UIImage imageNamed:@"Magneton"],[UIImage imageNamed:@"Marowak"],[UIImage imageNamed:@"Mewtwo"],[UIImage imageNamed:@"Moltres"],[UIImage imageNamed:@"Mr Mime"],[UIImage imageNamed:@"Muk"],[UIImage imageNamed:@"Nidoking"],[UIImage imageNamed:@"Nidoqueen"],[UIImage imageNamed:@"Ninetales"],[UIImage imageNamed:@"Omastar"],[UIImage imageNamed:@"Onix"],[UIImage imageNamed:@"Parasect"],[UIImage imageNamed:@"Persian"],[UIImage imageNamed:@"Pidgeot"],[UIImage imageNamed:@"Pinsir"],[UIImage imageNamed:@"Poliwrath"],[UIImage imageNamed:@"Porygon"],[UIImage imageNamed:@"Primeape"],[UIImage imageNamed:@"Raichu"],[UIImage imageNamed:@"Rapidash"],[UIImage imageNamed:@"Raticate"],[UIImage imageNamed:@"Rhydon"],[UIImage imageNamed:@"Sandslash"],[UIImage imageNamed:@"Scyther"],[UIImage imageNamed:@"Seadra"],[UIImage imageNamed:@"Seaking"],[UIImage imageNamed:@"Slowbro"],[UIImage imageNamed:@"Snorlax"],[UIImage imageNamed:@"Starmie"],[UIImage imageNamed:@"Tangela"],[UIImage imageNamed:@"Tauros"],[UIImage imageNamed:@"Tentacruel"],[UIImage imageNamed:@"Vaporeon"],[UIImage imageNamed:@"Venomoth"],[UIImage imageNamed:@"Venusaur"],[UIImage imageNamed:@"Victreebel"],[UIImage imageNamed:@"Vileplume"],[UIImage imageNamed:@"Weezing"],[UIImage imageNamed:@"Wigglytuff"],[UIImage imageNamed:@"Zapdos"], nil];
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
{
pokemonImageView.frame = CGRectMake(10, 10, 25, 25);
[pokemonImageView setImage:[UIImage imageNamed:[imageArray objectAtIndex:row]]];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(55, 10, 25, 25)];
nameLabel.text = [pokemonArray objectAtIndex:row];
nameLabel.textAlignment = NSTextAlignmentRight;
nameLabel.backgroundColor = [UIColor clearColor];
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 367, 300)];
[newView insertSubview:pokemonImageView atIndex:0];
[newView insertSubview:nameLabel atIndex:1];
return newView;
}