【发布时间】:2017-05-22 14:31:52
【问题描述】:
Output image实际上我是目标 c 的新手。我的问题是如何从带有标签的文本字段中获取文本。文本字段位于嵌套的 uistackview 内。所以我无法从嵌套的 uistackview 中获取文本字段的值。如何使用objective c从stackview中获取文本?
如图所示,我仅从最后一个文本字段而不是从以上两个文本字段获取文本。我是动态创建的文本字段,我应该如何获取每个文本字段的文本?
else if ([key isEqualToString: textbox]){
NSDictionary *widthAndHieght = [rowNames objectForKey:key];
//NSLog(@"Hieght: %@",[widthAndHieght objectForKey:@"height"]);
//NSLog(@"Width: %@",[widthAndHieght objectForKey:@"width"]);
int height = [[widthAndHieght objectForKey:@"height"]intValue];
int width = [[widthAndHieght objectForKey:@"width"]intValue];
NSString *intTag = [[widthAndHieght objectForKey:@"tag"] objectForKey:@"tagInt"];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, width, height)];
myTextField.borderStyle = UITextBorderStyleRoundedRect;
myTextField.font = [UIFont systemFontOfSize:15];
//NSString *textFieldTag = [NSString stringWithFormat:@"%@", tagValue];
//NSString *textFieldTag = myTextField.text;
NSInteger b = [intTag integerValue];
myTextField.tag = b;
NSLog(@" Textfield tag:%ld",(long)myTextField.tag);
myTextField.keyboardType = UIKeyboardTypeDefault;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//[layout addSubview:myTextField];
[layout addArrangedSubview:myTextField];
NSNumber *tagNumber = [NSNumber numberWithInteger:b];
[arrayOfTagValue addObject:tagNumber];
NSLog(@" tag values :%@",arrayOfTagValue);
NSDictionary *bindings3 = NSDictionaryOfVariableBindings(layout, myTextField);
// Set the constraints for the label to be pinned equally with padding
[greyView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(30)-[myTextField]-(30)-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:bindings3]];
[greyView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(30)-[myTextField]-(30)-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:bindings3]];
}
下面是我需要获取每个文本值但无法实现的代码。怎么做?
-(void) sendBridge:(UITextField *)textField{
for(int i = 0; i< [arrayOfTagValue count]; i++){
NSLog(@"Value :%@",[arrayOfTagValue objectAtIndex:i]);
if(textField == myTextField) {
myTextField.textColor = [UIColor redColor];
NSLog(@" text :%@",myTextField.text);
}
}
}
【问题讨论】:
标签: ios objective-c uistackview