我正在创建自定义视图,因为我添加了选择器,当did selected
在选择i之后在索引方法中的行将从superView中删除选择器,但App将崩溃。如果不从superview
删除它将不会崩溃。我能做什么请建议我。
我会在选择文本字段时使用选择器
_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];
现在Picker方法存在问题
-(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];
}
如果我从[pickerView removeFromSuperview];
方法移除didselectRow
,它将正常工作,但我想在选择选择器之后必须从超视图中移除。如果它不会崩溃并显示错误“(lldb)”像这样。
答案 0 :(得分:0)
将其更改为以下内容:
var floatVal = 34.55;
value1 = Math.round(floatVal); // it will be 35
$('#input1').attr("data-floatVal","34.55");
$('#input1').val(value1);
//it's important to parseFloat
value2 = parseFloat($("#input1).attr("data-floatVal"));
答案 1 :(得分:0)
使用此 - [pickerView setHidden:YES];