应用程序崩溃没有堆栈跟踪uipickerview与textfield

时间:2014-08-17 21:51:41

标签: ios delegates uipickerview textfield

在尝试编辑文本字段时,我仍在努力获取UIPickerview,但现在我的应用程序崩溃而没有任何堆栈跟踪。而不是堆栈跟踪它只显示通常((lldb))然后没有

#import "TestViewController.h"
#import "FindClasses.h"

@interface TestViewController ()
@property UIPickerView *picker;
@property NSArray *pickerArray;
@property (nonatomic, strong) FindClasses *finder;
@end

@implementation TestViewController

@synthesize finder = _finder;

- (FindClasses *)finder
{
    if (!_finder) _finder = [[FindClasses alloc] init];
    return _finder;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.pickerArray = [self.finder findClassesInTimetable];

    self.classField.delegate = self;
    self.picker = [[UIPickerView alloc] init];
    self.picker.delegate = self;
    self.picker.dataSource = self;
    self.classField.inputView = self.picker;
    // Do any additional setup after loading the view.
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField  {
    [textField becomeFirstResponder];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIPickerView method implementation

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


-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.pickerArray.count;
}


-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [self.pickerArray objectAtIndex:row];
}

有人为什么会一直这样? 感谢。

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,并通过包含此代码解决了问题。

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
[self. textField resignFirstResponder]; //Once the user clicks return field on number pad, it resignsfirstresponder "textField"
double delayInSeconds = 0.3; //set delaytimer to .3 seconds
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); //Set pop time
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self openPickerView]; }); //open pickerview after .3 sec time delay
return YES; //BOOL function hence return either true or false. In this case, it is true.
}

- (void)openPickerView
{
[UIView beginAnimations:nil context:nil]; //Begin animation set to nil
[UIView setAnimationDuration:0.3]; //Animation duration in 0.3 sec
pickerViewContainer.frame=CGRectMake(0, 200, 320, 261); //Open picker view with the mentioned x axis,y axis, width,height details
[UIView commitAnimations]; //Commit animation
}