简体   繁体   中英

UITextField inputview to pop up UIPickerView displaying question mark in pickerview

Here is my .h file

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

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;

I believe it should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM