I'm new to objective C, I have a view based application which communicates with a web service and recives an xml, parse it and map its contens an appropriate view component (e.g if thats a date show the question with datepicker, if question has 2 values show it with a segmented control, if more with a pickerview..etc) so its a dynamic questionary with many pages filled with multiple components.
how can I do the design for the mapping the xml response into related UI view components on runtime? I want to make the code as object orient as possible and not too many if elses in my view controller class, but instead it should only receive a let's say "uiview object" filled with necessary view components and it will just show it. I have a UiScrollView and want to add new different approprite Uicomponents(Picker, textbox, label..) to it on real time, How can I do this? I think in the Interface builder I only need to put the scrollview and the rest will be in code? and using a scrollview a good choice here? thanks.
[self.view addSubView: imageview];
[self.scrollView addsubview:pickerview];
[self.view addSubView:scrollview];
like wise the custom view may be like uibutton,textfield,textview,imageview
you can't do without a UIScrollView. you have to define the set of elements you wan to inject into your view and make case statement for the xml data you are receiving in your receiving data handler.
If you are new to Objective-C (i.e. CocoaTouch) and if your polls are fixed enough , maybe you could try setting up the differents views in the code and the data you are retrieving from the net will be to decide which view to display.
another tip will be to subclass UIKit elements to init them from a XML node.
Related
I want to make the horizontal swipeable page like YouTube. Is there an object in XCode for this? How do I have to do it? I did not find a tutorial about it. Sorry for my English.
Like this
There are tons of components already made for this in the internet, you can try looking at the cocoacontrols site.
If you still want to write your own code for this, one way is writing a custom UIView subclass. The YouTube feature looks very simple and as far as I can guess, they can use two separate UIView subclasses: one for the menu and one for the pages, just as a container.
For the menu you can use UIStackViews or a single UIViews with UIButtons for the page's titles and another view for the selection effect that moves with the UIButton's touch event. This view should provide a delegate or any notification system that fits better to you in order to notify the container that needs to load the right UIViewController's view inside the container.
The container can be a UIView that loads the view property from the UIViewController subclass on demand. Make sure to add the loaded view controller as a child of the parent view controller, otherwise you will loose some important features.
I hope it can help you to start.
I'm trying to create a generic, reusable view, that looks like a lined notepad. The way I decided to approach the problem (after a couple design iterations) is to create a custom view that is composed of a UITextView and a UIView.
When the user scrolls through lines of text I want the UIView to track the scroll direction. The key here is: Within my custom view, I need to change the position of one subview in response to events in another subview. Something needs to coordinate these changes...
Now, one approach I thought of taking was to use a MVC design pattern. A view controller could handle all events and move the subviews around accordingly. This MVC could then be embedded in other MVCs.
Normally when using a MVC design pattern, a controller would handle user events and manipulate the model and view. However, my custom view doesn't have a model - all I'm trying to do is have the view manage it's own subviews when a user does something like scroll. It seems to me that the MVC design pattern isn't a good fit here for two reasons:
There isn't a model or logic that is specific to the program it's being used in.
It seems to me that the view should be responsible for handling user events that change how the view should appear.
... but I could be wrong, which is why I'm asking for help. The question, for those who are more experienced than I and who may have done this many times before, is:
What type of design pattern is appropriate in this situation? MVC or...
You want a view to manage its own subviews? Then do that! So what if that pattern doesn't have a TLA?
A typical approach is to implement layoutSubviews in your container view. Have it check its current state, or the state of the other views in the window (e.g. the contentOffset of a scroll view), and then set up its subviews appropriately. (Resize them, reposition them, etc.)
Just try to keep it fast, since it's likely that layoutSubviews will be called frequently.
I have a multi-component UIPickerView in my application. Two components are plain and completely served by the pickerView:titleForRow:forComponent: method. My third component however requires a custom view via the pickerView:viewForRow:forComponent:reusingView: method. I don't see any way in the documentation to have a "partially customized" UIPickerView where some components use ...titleForRow... and some use ...viewForRow.... Is this possible? If so, how does one do that?
You've got to go all or nothing. The plain, boring default views are pretty much just a UILabel. You should be able to easily recreate this view.
I have an application with multiple views that contain subviews. I know that you can hide or make visible a view and its subviews by setting the hidden property to YES or NO. However with a number of views, to use the hidden property requires keeping track of what view is being displayed. I thought I could use sendSuBViewToBack: to hide a view and moveSubViewToFront to make it visible. However, these methods appear to only act on the specific subview and not its child subviews. For example, a view with a couple of labels on it, when sent to the back, the labels remain visible.
Is there any way to make this behavior work besides using the hidden property?
Thanks,
Jim
UIViewController seems like what you're looking for. Or rather, what you should be looking for.
I'm not quite sure what exactly you're having trouble with here. As long as you're keeping track of each "container" view (perhaps using a #property), you should be able to show/hide them on demand using a method in your code (which can be as simple as hiding all container views, and then showing the one you desire).
I am quite new to the whole IPhone development thing and was playing around with the Three20 library. The samples for this library showed me an easy way to create a nice looking button with styles etc and this to my view:
TTButton* button = [TTButton buttonWithStyle:#"forwardActionButton:" title:#"Login"];
[button setFrame:CGRectMake(245, 160, 65, 33)];
[self.view addSubview:button];
Works great. Now I have created a nib file in interface builder with my whole view layed out including all sorts of textfields etc.
What I would like to do is, is to create a placeholder for a button in Interface Builder and in my viewDidLoad method replace this placeholder with the actual TTButton instance. This would prevent my from having to call setFrame with an hardcoded location and instead make the whole interface design process much more free.
I have already tried creating a UIView object in interface builder, changing the type to TTButton and then assigning a new instance but seems to put the new button at coordinates location 0,0.
Can anybody point me in the right direction on how to achieve this?
waseem,
Unfortunately three20 does not use interface builder at all. The best thing you can do is layout a mock-up view and grab button x-y locations from that, then use those to update your TTButton locations in code.