0

I am working on a screen where user selects an option from drop-down. Based on this selection he adds a bunch of controls to screen. My drop-down is at the bottom-right corner of the screen. It takes up 20-25% of screen space at the bottom. In the remaining 75% screen at the bottom i need to add 9 labels,6 UItext fields ,2 drop-downs and 2 buttons. I am attaching a markup here.

My question is: in ASP.NET, I have a repeater which has all the above controls. In one of the buttons named "Add More". If I click that button, it adds the same repeater at the bottom of the current one. Do we have anything like that in iOS? Like a repeater which has a bunch of controls and click add and that exact repeater is added at the bottom and so-on and so forth. If any ideas/new ideas based on my explanation pop-up then please let me know. Thanks.

The link http://dl.dropbox.com/u/40597849/mockup2.png

So, the big rectangle to the right containing 8 labels, textboxes, drop-downs and the 2 buttons below it(one is named as "Add More") should be added again when user clicks on Add More. Please ask me if you need more information.

ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:frame];
cView.delegate =self;
CGPoint scrollPoint = CGPointMake(0.0, (frame.origin.y/400)*400);
[self.scrollView setContentOffset:scrollPoint animated:YES];
[self.scrollView addSubview:cView];

Initially the very first custom view i add, i add it with this frame size (187, 585, 350, 21); . Next whenever i hit add more i call this delegate

[self.delegate addNewSize:CGRectMake(187,self.y+ 400 , 400, 400)];

This calls the above 5 lines of code and makes a new custom view and adds it to scroll view. I store the self.y as the y value of whatever frame currently being built. So how do i make my scroll view move up and down freely. The screen shows the custom view as they are added but doesnt allow me to go up anymore. I wanted to suppose add the custom view 5 times and i added 4 i just want to scroll up , see i added 4 scroll down and just add 1 more custom view and do other processing with it. But my scroll view is non-functional and its stuck at the just added custom view disabling me to scroll up. If you need more information, please ask me. Thanks.

RookieAppler
  • 1,517
  • 5
  • 22
  • 58
  • `UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [self.view addSubview:btn];`, extend and configure as you wish. –  Dec 12 '12 at 19:03
  • @H2CO3. Thanks. I did try that. I can add buttons,labels,etc dynamically. My question is can we add all the controls to a "special custom control" and when user clicks "Add More", add this control at the bottom. Does iOS have such a thing (like repeater in ASP.NET). – RookieAppler Dec 12 '12 at 19:07
  • I don't think so, but this way you can implement your own. –  Dec 12 '12 at 19:08

1 Answers1

4

Use a custom view that contains all your views.

1.) Make a custom class myView which subclasses UIView.
2.) Add all the controls you need in that view class.
3.) include myView in your main view.
4.) initiate as many myView as you like and add them to your main view.

I hope that is clear enough to get you going.


Update: As to elaborate more on the comment bgoers made.
When you create a new class myView sub-classing UIView you get an empty sheet. This sheet will have the frame that you specify either in the class or when you initiate (up to you). Within that frame (myView.h and myView.m in initWithFrame), you can add subViews like buttons or labels. Those subviews will placed relative to the sheet myView.

For example, your draw up is a custom view with all the controls. I can have another one looking exactly like it by simply initiating another custom view without adding more subviews. All I need to do is move the second custom view to where I would like, all the subviews will follow.

I encourage you to read up on how to subclass and how that works in iOS. It is very simple once you get the hang of it.

Byte
  • 2,920
  • 3
  • 33
  • 55
  • Thanks. Ok i can make a view like that and add all my controls to it in .h file. But how do i make them be placed at specific locations. If you see my mockup.There are 6 labels in one line ,then 4 text fields and 2 drop downs in next line and 2 labels in the next line and 2 more text boxes below them. And then finally 2 buttons. So my controls are spread on 5 lines. How can i make them like that?How to spread them out like that. I am new to iOS. So forgive me if its a novice question. – RookieAppler Dec 12 '12 at 20:23
  • 1
    The controls are relative to a view's bounding box. So if you add a button inside myView, the coordinates would start at 0,0 top left FOR THAT VIEW. Then in the view controller that contains myView, you position the encompassing view wherever. It's all just relative positions and containers. So for instance, if I have myView, I can add as many controls as I want as subviews of myView. Then in the viewController, whenever I place myView, its subviews move with it because they are only relative to myView – anon_dev1234 Dec 12 '12 at 20:35
  • @bgoers. Thanks. So if i understand you properly, it seems i have to place all my controls with respect to origin. First place label at x,y location..then i do x+20 and place second label and x+20 and so on and so forth..this will place my controls at those locations right?When i use this myView in my ViewController i just make a call to initWithFrame and they are placed like they were created..Right? – RookieAppler Dec 12 '12 at 20:57
  • +1 to bgoers help explaining. @Phanindar Please see the update. – Byte Dec 12 '12 at 20:58
  • @Phanindar Yes - check the edit made to the answer. Let's say I am in the .m file for myView. I set my initial label position at 10,10. From there, I can set up the rest of the UI. Now back in the ViewController, I set myView's frame to be 400,400 - myView will be set there with its frame, and the subviews of myView will be offset from that 400,400 point. They are relative to myView, not the view controller that contains myView. – anon_dev1234 Dec 12 '12 at 21:14
  • @Byte. I got a question that is continuation.So i add the custom control. If i click "Add More" it adds the custom view again. I can keep going. Fine. But my scroll view is lost, i mean the "custom view" is at the bottom.When i click add more it adds the custom view and the other controls(controls that were above the "custom view") move up and up and up as i keep adding. But i cant drag the screen up down.Basically i want the scroll view to go up (very top) and down (to the last "custom view" that was added).I added some code.Please take a look at it and its explanation as well. Thanks – RookieAppler Dec 12 '12 at 23:07