UITextField inputview para que aparezca UIPickerView mostrando el signo de interrogación en la vista del selector

Aquí está mi archivo .h

When I run this code and select a text field, a pickerview pop's with question marks in it but when I select question mark I get correct values in text field

#import <UIKit/UIKit.h>

#import "ScrollableViewController.h"
#import "MIBackgroundTapDelegate.h"


//@interface Activapc1 : UIViewController {
@interface Activapc1 : ScrollableViewController <MIBackgroundTapDelegate, UIPickerViewDelegate, UIPickerViewDataSource>{   

UITextField *amplitude1;
UITextField *rate1;
UITextField *pulse_width1;
UITextField *impedance1;

IBOutlet UITextField *configuration;
NSArray *mode;

}

@property (nonatomic, retain) IBOutlet UITextField *amplitude1;
@property (nonatomic, retain) IBOutlet UITextField *rate1;
@property (nonatomic, retain) IBOutlet UITextField *pulse_width1;
@property (nonatomic, retain) IBOutlet UITextField *impedance1;

-(IBAction)next;
-(IBAction)skip;
-(IBAction)home;
-(IBAction)select;

-(IBAction)textFieldDoneEditing:(id) sender;

@end

Here is .m file

I am not able to understand why I am getting question mark please help me

#import "Activapc1.h"
#import "dbsViewController.h"
#import "Activapc2.h"
#import "APCoption.h"



@implementation Activapc1

@synthesize amplitude1;
@synthesize rate1;
@synthesize pulse_width1;
@synthesize impedance1;

const int MyModePicker = 3002;

-(void)viewDidLoad {
self.svScrollViewM.contentSize = CGSizeMake(320, 416);
[self registerForEditingEvents:amplitude1];
[self registerForEditingEvents:rate1];
[self registerForEditingEvents:pulse_width1];
[self registerForEditingEvents:impedance1];

UIPickerView *modePicker = [[UIPickerView alloc] initWithFrame:CGRectZero];
modePicker.tag = MyModePicker;
modePicker.delegate = self;
modePicker.dataSource = self;
[modePicker setShowsSelectionIndicator:YES];
configuration.inputView = modePicker;
[modePicker release];

[super viewDidLoad];

    //Prepare data for pickers
    mode = [NSArray arrayWithObjects:@"Voltage",@"Current",nil];



[mode retain];

//mode = [[NSMutableArray alloc] init];
//[mode addObject]
}

//********picker view code**************

#pragma mark -

#pragma mark UIPickerViewDelegate

-(NSString *)pickerView:(UIPickerView *)pickerView titileForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if(pickerView.tag == MyModePicker)
    {
        return [mode objectAtIndex:row];
    }
    return @"Unknown title";

}

-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
        if(pickerView.tag == MyModePicker)
        {
            configuration.text = (NSString *)[mode objectAtIndex:row];
        }
}

#pragma mark -

#pragma mark UIPickerViewDataSource

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView    numberOfRowsInComponent:(NSInteger)component
{
    if(pickerView.tag == MyModePicker)
    {
        return mode.count;
}
return 1;
}

#pragma mark -

//**********picker view code end************

-(IBAction) backgroundTap:(id) sender{
[self.amplitude1 resignFirstResponder];
[self.rate1 resignFirstResponder];
[self.pulse_width1 resignFirstResponder];
[self.impedance1 resignFirstResponder];
}

-(IBAction) textFieldDoneEditing:(id)sender{
[sender resignFirstResponder];
}

-(IBAction)home {
dbsViewController *dbs = [[dbsViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:dbs animated:YES];
}

-(IBAction)skip {
Activapc2 *activapc2 = [[Activapc2 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:activapc2 animated:YES];
}

-(IBAction)next {
Activapc2 *activapc2 = [[Activapc2 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:activapc2 animated:YES];
}

-(IBAction)select {
APCoption *apcoption = [[APCoption alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:apcoption animated:YES];
}




- (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 {
[mode release];
[super dealloc];
}



@end

preguntado el 09 de marzo de 12 a las 23:03

1 Respuestas

The pickerview needs a title not a titile. Also the delegate method that returns the string does not have a reusingView: parameter. Since you don't properly implement the delegate method the picker simply displays question marks.

-(NSString *)pickerView:(UIPickerView *)pickerView titileForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

Creo que debería ser:

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

respondido 09 mar '12, 23:03

Thanks Its working now, I also removed this reusingView:(UIView *)view statement in .m file, after that it was working - a lo grande

@bigbang Glad to help. It's nice to get a comment saying a solution worked. But you should also accept an answer for each of your questions that solved the issue for you. - NJones

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.