-1

I want to have a large number of text boxes which will be touch enabled and editable. Is creating NSArray of UItextField objects the best way for this? If Yes, How can I create? or Suggest other ways to achieve this.

Avin
  • 86
  • 11

3 Answers3

1

It largely depends on what you are trying to do. An NSArray as a way to store all the text boxes you are using in you controller (instead of creating ivars for that purpose) is ok, but you could as well use a UITableView/UITableViewController for that.

Using a table view would give allow you to grow the number of your text boxes without any effort. On the other hand, if you can guarantee that your text boxes will never be more than those you can display on a single screen real estate, I don't think using a table view would give you big advantages. But, as I said, this largely depends on what you are trying to do.

If you decide to go for the array option, I would suggest using an NSDictionary instead, so that you can access each one of your views by name (or tag, if you associate a tag with each one).

Also keep in mind that you could use the getViewByTag: method on your container view to get a reference to any view that it contains based on the view tag you assigned. So, you could do:

//-- creating text box:
UITextField* textBox = ....;
textBox.tag = 1;
[self.view addSbview:textBox];

//-- accessing the text box:
UITextField* textBox = [self.view getViewByTag:1];

In this sense, a view already behaves as a container for you text boxes and gives you access to them.

EDIT:

Actually I'm trying to create a crossword grid

ok, so, if it's 2-dimensional, I would say that a table view is ruled out (it is not impossible to do, but I think there are easier ways).

as to your question, it all depends on how dynamic your crossword grid is: does it always have the same number of rows and columns? or can it be defined by the user? etc.

In the first case, I would go for an NSArray, or I would simply use tagging as shown above (that would also make memory management automatic).

Otherwise, you might inspect UICollectionView.

If your question is: which data structure is more appropriate to handle a crossword puzzle? then, have a look at this post. In any case, I would say: do not expect that you find a ready-made solution for that kind of problems...

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • sorry for not being clear in first time, Actually I'm trying to create a crossword grid. But I could not figure out which way to go. what will be best to use so that i can check the words formed by characters in each text box. – Avin Feb 05 '13 at 05:30
0

A UITableView containing editable cells would be the best way to do this, if you're after what I think you're describing. There's lots of sample code on Apple's developer site detailing how best to use a table view to create a view showing a series of editable text inputs.

lxt
  • 31,146
  • 5
  • 78
  • 83
0

Better to use UI Table View instead of adding 'n' number of text fields.

Madhu
  • 1,542
  • 1
  • 14
  • 30
  • How can we have multiple row and columns of text boxes in Table view. Please suggest any tutorial link for that. – Avin Feb 05 '13 at 05:32
  • 1
    Just go through simple Apple Documentation of UITableView & follow the sample example of multiple records. You will get what your expecting. – Madhu Feb 05 '13 at 05:37