0

我想通过 for 循环加载我的选择器。从 1 到 999。我手动加载。

我的代码在这里。我如何使用“for 循环”自动加载。谢谢

- (void)numberWasSelected:(NSNumber *)selectedIndex element:(id)element;

@synthesize numbers = _numbers;

@synthesize selectedIndex = _selectedIndex;

self.numbers = [NSArray arrayWithObjects:@"1", @"2", @"3",............@"999" nil];

- (IBAction)selectNumbers:(UIControl *)sender {
[ActionSheetStringPicker showPickerWithTitle:@"Select a number !" rows:self.numbers  
initialSelection:self.selectedIndex target:self    
successAction:@selector(numberWasSelected:element:) 
cancelAction:@selector(actionPickerCancelled:) origin:sender];

}

 - (void)numberWasSelected:(NSNumber *)selectedIndex element:(id)element {
self.selectedIndex = [selectedIndex intValue];


self.numberTextField.text = [self.numbers objectAtIndex:self.selectedIndex];

  }
4

1 回答 1

1
NSMutableArray* array = [NSMutableArray new];
for (int i = 1; i <= 999; i++) {
    [array addObject:[NSString stringWithFormat:@"%d", i]];
}

self.numbers = array;
于 2013-06-04T12:42:12.047 回答