iphone - 如果我在选择器旋转时使用完成按钮关闭 UIPickerview 的操作表,则获取空值

标签 iphone objective-c ios uipickerview

我有一个 UIActionSheet包含 pickerUIToolbar .在 UIToolBar 上有一个完成按钮。然而,当我旋转 Picker如果我点击 Done,则组件在它停止旋转之前按钮,那么我的 UITextfield 中没有任何值(value).如果我点击 Done选择器停止旋转动画后的按钮,然后我得到所选组件的值

有没有办法在停止动画之前获得项目的值(value)..?

解决

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
     UILabel *lbl = (UILabel *)view;

           // Reuse the label if possible...
           if ((lbl == nil) || ([lbl class] != [UILabel class])) {
               CGRect frame = CGRectMake(0.0, 10.0, 250, 50);
               lbl = [[[UILabel alloc] initWithFrame:frame] autorelease];
           }
    if (component == 0) {

        lbl.textColor = [UIColor blackColor];
        lbl.textAlignment=UITextAlignmentLeft;
        lbl.backgroundColor = [UIColor clearColor];



        lbl.text = [arrCountry objectAtIndex:row];
        lbl.font=[UIFont boldSystemFontOfSize:14];
         NSInteger clm1 = [pickerView2 selectedRowInComponent:component];


        txtCountry.text = [arrCountry objectAtIndex:clm1];
        countryCode=[arrCountryCode objectAtIndex:clm1];
    }

    return lbl;
}

并且
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

  txtCountry.text = [arrCountry objectAtIndex:row];
  countryCode=[arrCountryCode objectAtIndex:row];
}

最佳答案

我不认为你可以交配。 UIPicker 仅在微调器停止时调用 didselectrow ,否则它会卡在先前选择的行上。在你的情况下的第一个。

最接近使用 uipicker 获得功能的是这个委托(delegate)方法:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

您必须查看屏幕上的 View 及其与中心的偏移量。除此之外,您可以实现自己的 ScrollView 并拥有一个 uipicker 覆盖,但这涉及大量工作。

或者!您可以告诉您的用户以正确的方式使用 uipicker,哈哈。

阻止用户按下保存的另一种方法是检测 uipicker 是否正在旋转。我找到了this to help你。

关于iphone - 如果我在选择器旋转时使用完成按钮关闭 UIPickerview 的操作表,则获取空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13284703/

相关文章:

ios - Realm .io : Persist an enum

iphone - 人像年龄渐进算法

iphone - 从 subview 导航 Controller 访问顶部导航 Controller

ios - 在 iPhone 上使用 splitviewcontroller 先描绘细节 View

iphone - 下载并保存可以为空白的图像

iOS - Swift - 使用 Alamofire 的必应图像搜索 API 身份验证

ios - Obj-c - 返回原始状态时延迟动画?

iphone - 以编程方式创建 UITextField iphone 时出现问题

iphone - AVCaptureSession 指定自定义分辨率

ios - 如何在多个设备上使用 EventKit 同步 iOS 上的事件