My PcikerView only show "?"

Discussion in 'iOS Programming' started by mikezang, Jul 14, 2010.

  1. macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I made a PickerView as below, but when I run it, I can only view "?" in my PickerView, I am not sure why, can you help me?
    Code:
    #import <UIKit/UIKit.h>
    @interface SingleComponentPickerViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
    	UIPickerView *singlePicker;
    	NSArray *pickerData;
    }
    @property (nonatomic, retain) IBOutlet UIPickerView *singlePicker;
    @property (nonatomic, retain) NSArray *pickerData;
    -(IBAction) buttonPressed;
    @end
    
    Code:
    #import "SingleComponentPickerViewController.h"
    @implementation SingleComponentPickerViewController
    @synthesize singlePicker;
    @synthesize pickerData;
    -(IBAction) buttonPressed {
    	NSInteger row = [singlePicker selectedRowInComponent:0];
    	NSString *selected = [pickerData objectAtIndex:row];
    	NSString *title = [[NSString alloc] initWithFormat:@"You selected %@!", selected];
    	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"Thank you for choosing." delegate:nil cancelButtonTitle:@"You are Welcome" otherButtonTitles:nil];
    	[alert show];
    	[alert release];
    	[title release];
    }
    typically from a nib.
    - (void)viewDidLoad {
    	NSArray *array = [[NSArray alloc] initWithObjects:@"Luke", @"Leia", @"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando", nil];		       
            self.pickerData = array;
    	[array release];
    }
    -(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    	return 1;
    }
    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    	return [pickerData count];
    }
    -(NSString *) pcikerView:(UIPickerView *)pcikerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    	return [pickerData objectAtIndex:row];
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
    }
    - (void)viewDidUnload {
    	self.singlePicker = nil;
    	self.pickerData = nil;
    	[super viewDidUnload];
    }
    - (void)dealloc {
    	[singlePicker release];
    	[pickerData release];
        [super dealloc];
    }
    @end
    
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    First, where do you set your UIPickerView's delegate?

    Second, this delegate method has a typo in the name:
     
  3. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    What do you mean "where to set delegate"?
    Do you mean in xib file?
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Do you understand what setting a delegate means?
     
  5. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #5
    I set both delegate and DataSource to UIPickerView in my nib file
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Good. That answers my question then.
     
  7. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #7
    Here is my settings
     

    Attached Files:

  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Did you fix your delegate method name typo yet?
     
  9. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #9
    Why do you mean? I am not sure what do you talk....

    Can you tell me which name I should modify?
     
  10. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    If my first post in this thread isn't enough info for you, I'm afraid I can't help you. I'm out.
     
  11. macrumors 65816

    Joined:
    Jul 6, 2007
    #11
    It was shown in post #2. Here it is again: (pickerView is spelled wrong)

    Code:
    -(NSString *) [size=7]p[b]ci[/b]kerView:[/size](UIPickerView *)[size=7]p[b]ci[/b]kerView[/size] titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    	return [pickerData objectAtIndex:row];
    }
    
     
  12. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #12
    OH, My god?

    Sorry for my miss, now I got what I need.

    Thanks for your patient:)
     
  13. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    You're welcome. Just remember that precision is an important skill to hone in programming. Also, I try to copy delegate method syntax from right out of the documentation. This helps reduce typos to a large extent. If there is a typo, it's Apple's fault, not mine. :)
     

Share This Page