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.
I want to have a large number of text boxes which will be touch
Share
It largely depends on what you are trying to do. An
NSArrayas 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 aUITableView/UITableViewControllerfor 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
NSDictionaryinstead, 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:In this sense, a view already behaves as a container for you text boxes and gives you access to them.
EDIT:
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…