我是 iOS 的新手我需要使用 objectAtIndex(0)
<在 textfield 中显示uipickerview
/ em> .while在选择器视图中选择后运行应用程序文本字段为空只有值可以在textfield中显示我需要最初textfield不为空。
viewdidload
代码:
pktStatePicker .delegate = self;
pktStatePicker .dataSource = self;
[ pktStatePicker setShowsSelectionIndicator:YES];
txtText.inputView = pktStatePicker ;
// Create done button in UIPickerView
UIToolbar* mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
mypickerToolbar.barStyle = UIBarStyleBlackOpaque;
[mypickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[mypickerToolbar setItems:barItems animated:YES];
txtText.inputAccessoryView = mypickerToolbar;
选择器视图委托:
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog([arrmsg1 objectAtIndex:row]);
txtText.text = (NSString *)[arrMsg objectAtIndex:row];
}
答案 0 :(得分:0)
在ViewDidLoad
上设置,但请确保arrMsg.count!=0
- (void)viewDidLoad
{
[super viewDidLoad];
txtText.text = (NSString *)[arrMsg objectAtIndex:0];
}
<强>选择-2 强>
或者在该调用之后将数据附加到arrMsg中,如
if (arrMsg.count >0)
{
txtText.text = (NSString *)[arrMsg objectAtIndex:0];
}
继续你的工作之后