Re: Creating More Than 1 Of The Same Element/control
Re: Creating More Than 1 Of The Same Element/control
- Subject: Re: Creating More Than 1 Of The Same Element/control
- From: Graham Cox <email@hidden>
- Date: Thu, 23 May 2013 09:55:44 +1000
On 18/05/2013, at 8:21 PM, Harmony Neil <email@hidden> wrote:
> I've been working through a couple of tutorials and managed to make a text field and things just fine. The thing I'm wondering is how do I go about naming the textField what I want to call it, like textField1 or for example rather than just textField? Also, how do I make more than 1 textField? I would just use the same code as for the first one and change the y co-ordinate, but then I would still want to call them all something other than textField.
> I'm using the objective c language and hate using the storyboard and interface builder. If I'm going to code something, I'll write the code by hand. I tried posting on the objc language list, but the only person who replied seemed to think it was too beginner level and that I was posting on the wrong list. If no one on here can help me rather than insist on suggesting stupid books, I don't really know where else to ask, since I'm not getting a lot of luck on google's search results.
Stick with Interface Builder, even if you don't enjoy it right now. You'll come to appreciate it even if it will perhaps never be love.
All you need to do is to create a separate IBOutlet in the controller for each field, then connect that to the fields in IB. In code, you can refer to the outlet by whatever name you called it, like any other instance variable.
@interface MyController : UIViewController
{
IBOutlet UITextField* mTextField1;
IBOutlet UITextField* mTextField2;
}
@end
in the code....
[mTextField1 setStringValue:@"blah blah"];
[mTextField2 setStringValue:@"hubba hubba"];
Trying to do the set up of this kind of thing in code is possible, but never a very good idea. It is certainly the sign of a beginner to want to do that; you'd really be much better off using the time to get more familiar with IB. It will truly save you a monumental amount of work and will eliminate many irritating typical bugs.
I infer that you're working in iOS, rather than Mac, but I might have got the class names wrong above. I'm sure you're smart enough to realise if that's the case.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden