I am creating custom view, in that i added picker, when did selected
Row at index method after selecting i will removed the picker from superView, but App will crashing. if will not remove from superview
it will not crash. what can i do Please suggest me .
I will using picker when textfield selecting
_rUsername=[[UITextField alloc]initWithFrame:CGRectMake(15, 270, self.view.frame.size.width-30, 30)];
_rUsername.backgroundColor=[UIColor whiteColor];
_rUsername.placeholder=@"Gander";
[_rUsername addTarget:self action:@selector(showPicker)forControlEvents:UIControlEventEditingDidBegin];
[_registerView addSubview:_rUsername];
now problem in Picker methods
-(void) showPicker
{
[_rUsername resignFirstResponder];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(30,230,220,0)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[_registerView addSubview:pickerView];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [_arrayNo count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_arrayNo objectAtIndex:row];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;
return sectionWidth;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
_rUsername.text=[_arrayNo objectAtIndex:row];
[pickerView removeFromSuperview];
}
Here if i removed [pickerView removeFromSuperview];
from didselectRow
method it will working fine, but i want after selecting picker must remove from the superview. if it will not then crashed and shows error "(lldb)" like this .
Change it to the following:
pickerView.hidden = true;