سؤال

وأود أن تظهر مجموعة من الأرقام متتالية في مكون UIPickerView ولكن يكون ذلك التفاف حول مثل عنصر ثانية من تطبيق بين الساعة> الموقت. سلوك الوحيد الذي يمكنني تمكين يشبه عنصر ساعات من التطبيق الموقت، حيث يمكنك التنقل في اتجاه واحد فقط.

هل كانت مفيدة؟

المحلول

وانها مثلما من السهل تعيين عدد الصفوف لعدد كبير، وجعلها تبدأ في قيمة عالية، وهناك فرصة ضئيلة أن المستخدم سوف انتقل من أي وقت مضى عجلة لفترة طويلة جدا - وحتى ذلك الحين، أسوأ ما سيحدث هو أنها سوف تصل القاع.

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    // Near-infinite number of rows.
    return NSIntegerMax;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    // Row n is same as row (n modulo numberItems).
    return [NSString stringWithFormat:@"%d", row % numberItems];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.pickerView = [[[UIPickerView alloc] initWithFrame:CGRectZero] autorelease];
    // ...set pickerView properties... Look at Apple's UICatalog sample code for a good example.
    // Set current row to a large value (adjusted to current value if needed).
    [pickerView selectRow:currentValue+100000 inComponent:0 animated:NO];
    [self.view addSubview:pickerView];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSInteger actualRow = row % numberItems;
    // ...
}

نصائح أخرى

ولقد وجدت جوابي هنا:

http://forums.macrumors.com/showthread.php ؟ p = 6120638 & تسليط الضوء = UIPickerView # post6120638

وعندما يسأل عن عنوان على التوالي، وإعطائها: الرمز:

return [rows objectAtIndex:(row % [rows count])];

وعندما يقول didSelectRow المستخدم: inComponent:، استخدام شيء من هذا القبيل:

والرمز:

//we want the selection to always be in the SECOND set (so that it looks like it has stuff before and after)
if (row < [rows count] || row >= (2 * [rows count]) ) {
    row = row % [rows count];
    row += [rows count];
    [pickerView selectRow:row inComponent:component animated:NO];
}

ويبدو أن UIPickerView لا يدعم التفاف حول أصلا، ولكنك تستطيع أن تخدع ذلك عن طريق إدراج أكثر من مجموعات من البيانات ليتم عرضها وعندما توقف منقار، تركز عنصر إلى وسط مجموعة البيانات.

ومجرد إنشاء مجموعة عدة مرات، بحيث يكون لديك لديك أرقام عدة مرات. دعونا نقول عندما ترغب في الحصول على أرقام 0-23 ووضع ذلك في صفيف. أننا سنبذل 10 مرات مثل هذا ...

NSString *stdStepper;

    for (int j = 0; j<10; j++) {
        for(int i=0; i<24; i++)
        {
            stdStepper = [NSString stringWithFormat:@"%d", i];

            [_hoursArray addObject:stdStepper];

        }
    }

وبعد ذلك وضعنا الصف 0 اختيار مثل هذا

[_hoursPickerView selectRow:120 inComponent:0 animated:NO];

وجميع الإجابات لا نحرز حقا عرض منتقي التمرير دوريا.

ولقد جعلت من tableView دوري بناء على UIScrollView. وبناء على هذا tableView، وإعادة تنفيذ UIPickerView. كنت قد تكون مهتمة في هذه DLPickerView. وهذا الرأي منقار لديه كل الميزات التي UIPickerView لديها، ولكن يعطي أيضا العديد من الميزات الجديدة، والعرف هذا الرأي منقار هو أسهل من ذلك بكثير.

https://github.com/danleechina/DLPickerView

ويكون على بينة من أن هذا DLPickerView التمرير دوريا والتمرير حقا دوريا. حدث كل السحر بسبب DLTableView فئة أخرى.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top