uiview - How to call a tagged textfield -
I am creating a series of programs using tags, I want to be able to access the data in each text field, But it is returning to the previous tag.
In this example, I am creating 10 textfields when you click on a field, then that area should be changed to blue, but it always changes the last field blue.
How do I use field tags, so that I can reach the right textfield?
I added NSOL to test the sender #.
@implementation ViewController @ synthesis name = _name; - (zero) viewDidoadload [[Super Viewedload]; Int y = 20; For (int i = 1; i Edit: This is great thanks. This certainly resolved one of my problems, I think I was hoping for a different answer that would take me in one direction to solve my second problem. I want to take input from a tagged textfield to use elsewhere. I have only one problem that I am only getting input from the previous textfield. - (zero) viewDidoadload {[Super Viewedload]; Int y = 20; (Int tag = 1; tag & lt; = 10; tag ++) {CGRect frame = CGRactam (20, Y, 100, 30); Name = [[UITextField alloc] initWithFrame: frame]; [Name set tag: tag]; [Name setbackgram color: [UIColor whiteColor]]; [Name addTarget: self-acting: @sillector (make etc.) for control events: UIControlEvent EditingDidend]; [Self.view addSubview: name]; [Name Set Delegate: self]; Y + = 38; }} - (Zero) CreateIATO: (ID) sender {int tag = (int) [sender tag]; [Name set tag: tag]; NSString * aName = [name text]; NSLog (@ "% @", anonymous); } In this example, I do not need to use the set tag again in the METSO method, but I do not know how to get a value from a particular tag.
In your makeBlue: Assign from. This view does not change even if you change your tag, the variable will point to the last view created in the name loop. If you want to use ideas by using tags: [self.view viewWithTag: & lt; Tag: Then your makeBlue: code will look like this: - (zero) macw: (id) Sender {int tag = (int) [Sender tag]; UIView * tagView = [self.view viewWithTag: tag] [tagviewback color color: [UIColor blueColor]]; } Therefore, you will use the value of a text field:
name = [self.view viewWithTag: [sender tag]]; NSString * fieldText = name.text;
Comments
Post a Comment