小编Oll*_*lie的帖子

设置多个UIPickerView的数据

我有两个UIPickerViews从数组中提取数据虽然我似乎无法单独编程.这是我用于UIPickerViews的代码:

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [treatments count];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
      return[[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    _buttonText.text = [[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
    if (![_buttonText.text isEqual: @"Pick a Treatment Name"]) {
        _buttonText.textColor = [UIColor blackColor];
    }
}

-(NSInteger)nursePicker:(UIPickerView *)nursePicker numberOfRowsInComponent:(NSInteger)component {
    return [nurses count];
}

- (NSString *)nursePicker:(UIPickerView *)nursePicker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return[[nurses objectAtIndex:row]valueForKey:@"nurseName"];
}
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,选择器显示相同的数据

提前致谢

iphone uipickerview ios

2
推荐指数
1
解决办法
2721
查看次数

- (CGRect)textRectForBounds:(CGRect)未被调用的边界

我试图在一个内部移动文本UITextField,使其垂直对齐正确.我在网上搜索过,所有内容都指向编辑这些方法:

- (CGRect) textRectForBounds:(CGRect)bounds
Run Code Online (Sandbox Code Playgroud)

- (CGRect) editingRectForBounds:(CGRect)bounds
Run Code Online (Sandbox Code Playgroud)

虽然我已经像这样编辑了它们:

- (CGRect) textRectForBounds:(CGRect)bounds {
    NSLog(@"hi");
    return CGRectInset(bounds, 10, 10);
}
Run Code Online (Sandbox Code Playgroud)

虽然它没有进入nslog.

我也尝试在文本字段上调用该方法,但没有成功

这是我初始化文本视图并设置它们的方式:

-(void) viewWillAppear:(BOOL)animated {
    textfield1 = [[UITextField alloc] init];
    textfield2 = [[UITextField alloc] init];
    textfield3 = [[UITextField alloc] init];
    textfield4 = [[UITextField alloc] init];
    for (UITextField *text in [NSArray arrayWithObjects:textfield1, textfield2, textfield3, textfield4, nil]) {
        text.delegate = self;
        text.placeholder = [placeholders objectAtIndex:i];
        text.frame = CGRectMake(10, offsetTop, container.frame.size.width - 20, 40);
        [text textRectForBounds:text.bounds];
        [text editingRectForBounds:text.bounds];
        text.borderStyle = UITextBorderStyleRoundedRect; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c padding uitextfield ios

1
推荐指数
1
解决办法
4418
查看次数

标签 统计

ios ×2

iphone ×2

objective-c ×1

padding ×1

uipickerview ×1

uitextfield ×1