UITextField输入视图弹出UIPickerView在pickerview中显示问号

时间:2012-03-09 23:24:53

标签: iphone xcode uipickerview

这是我的.h文件

当我运行此代码并选择文本字段时,其中会出现带有问号的选择器视图 但是当我选择问号时,我在文本字段中得到正确的值

#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

这是.m文件

我无法理解为什么我会收到问号请帮帮我

#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

1 个答案:

答案 0 :(得分:5)

挑选者视图需要标题而不是标题。返回字符串的委托方法也没有reusingView:参数。由于您没有正确实现委托方法,因此选择器只显示问号。

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

我认为应该是:

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