I'm new here, don't be very hard on me :)
Learning iOS development and trying to display a small view to enter some data to my app, which is using storyboards.
I tried adding it as subview but I can't move it from the top-left corner or make the background to fade. Any advice on how to do this?
Forgot to mention that this is for iPhone.
Thanks
Based on your comment it seems that you don't have a clear understanding of the difference between UIView and UIViewController.
Think of a UIViewController as your screen. Your screen might be showing many different views at once, but they are all part of the UIViewController's view.
Rather then present a new UIViewController (i.e. screen), you want to do something like this:
//Use a XIB for this, not a storyboard
UIView *newView = [[[NSBundle mainBundle] loadNibNamed:#"addData" owner:self options:nil] lastObject];
[self.view addSubview:newView];
I suggest reading these two guides from Apple until you understand the difference between a UIView and a UIViewController:
View Programming Guide
View Controller Programming Guide
Related
I would like to create a custom UIView so I could use it among a few UIViewControllers.
I created a xib file that looks like this:
The Above image has UIView, and inside 3 UIButtons
I created TopBar : UIView
I set the view size to freeform and the status bar to no.
I set the File's Owner class to TopBar
I dragged the UIView (which includes the 3 UIButtons) and called it contentView
I added in TabBar.m the method:
-(void)awakeFromNib {
[[NSBundle mainBundle] loadNibNamed:#"TopBar" owner:self options:nil];
[self addSubview: _contentView];
}
I added to my UIViewController via storyboard the UIView and set its class to TopBar and its size to the UIView size in the xib
However, the result looks like this:
Why? What is wrong? (as you can see the buttons are extremely big and have spaces between them). I am supporting only Ios6 and above
The problem was that auto-layout was checked in the xib file of TabBar.
I deselected it and now it displayed it property
If anyone needs, this shows how to deselect it in xcode 4.6
I am attempting to implement a UIScrollView with a UIPageControl following the guide on this website:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/
In opposite to the guide, I am implementing this in a storyboard project, and using XCode4.5.2. In addition to the code in the guide, I have added at the beginning of the #interface, and inside the viewDidLoad method in the implementation, I have added scrollView.delegate = self.
With only the code and IB-objects described in the guide added to my app, it doesn't allow me to scroll at all when I test it on my iPhone. The only scrolling i can do is by swiping my finger over the UIPageControl, which makes the "white dot" in the PageControl move one spot towards the direction I was swiping, and with no visible changes in the ScrollView. In the guide we add different colours to the backgrounds of the views in the scrollView -- none of these colours show up at all.
I have tried debugging by putting NSLogs in my code to see what methods are reached by the app. Adding an NSLog (#"View did load"); right after [super viewDidLoad]; in the viewDidLoad method atop the main view controller doesn't output anything to the terminal. Does this mean my app doesn't load up properly?
Thanks in advance!
Do you have multiple pages added to the scrollView? Scrolling is default off if you only have one page worth of content. Ensure that the loadScrollView method is called and also add this:
scrollView.pagingEnabled=YES;
If you are interested I created this class for paging with the scrollview
https://github.com/andrealufino/ALScrollViewPaging
Let me explain what I mean when I say that I want to rotate my subview too. I placed a lot of images to make my self clear. This may look like to much but it is not. Just wanted to be clear.
In the nib file that I am currently working on, I have a UIView and button.
The UIView that I created in interface builder is connected with the IBOutlet named ViewMain:
and the button executes the following method:
and what that method does is that it places the view from another nib file in the UIView controller that I created in interface builder. The nib file that I am actually placing is:
I just placed random controls to illustrate better my point.
so everything so far is great (the view from anotherViewController shows up on ViewMain when the user presses the button)
EVERYTHING LOOKS GREAT BUT NOTE WHAT HAPPENS WHEN I ROTATE MY DEVICE:
I would like my subview (anotherViewController.view) to ratate as well. I don't mind if it is bigger than ViewMain because I can have a transparent background. I just need to rotate it as well. How can I do that?
Define shouldAutorotateToInterfaceOrientation: in you UIViewController so that it always returns YES:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Look here for more details.
You should also take care to correctly define the autoresizing behavior of your view and subviews, so that everything is fine when autorotating.
EDIT:
to set the autoresize property for a view in Interface Builder, select the view then go to the "View Size" pane in the Info window and set "Autosizing" as in the image below.
I have some problems with the layout of my core plot graph.
To be more precise, I have created a GraphViewController (.h, .m and associated nib file). In the nib file I have added another UIView. This embedded view will be used to set the graph (as I do not want it to use the whole view). I then need to create a hosting view from this embedded view.
The embedded view is named graphView, I first though I needed to get the frame representing the graphView and create the hostingView so the graph will fit in the graphView. When I use the:
CPHostingLayerView *hostingView = [[CPHostingLayerview alloc] initWithFrame: [graphView frame]]
...
it does not work as expected, the graph does not fit the view (it is bigger than the graphView I created in IB)
Hope I am clear :(
Any idea would be more than welcome.
thanks a lot,
Luc
I finally find an answer :) Instead of adding an UIView within IB and programmatically create a CPLayerHostingView, I directly declared the view as an CPLayerHostingView in IB, that works perfectly.
Regards,
Luc
I was stuck with the same issue. What worked for me is a simpler way :
In super-view (where you are adding the core plot graph as a subview), add this code:
[self.subview.graphHostingView setFrame:self.view.bounds];
where subview is the view with the core-plot graph. And add this code 'after' you have done the graph initialization in the sub-view.
I know this has been talked about a lot. I think I've gone thru every question on this site, and still have not been able to get this working.
I'm new to developing but I have a good sense of what's going on with all of my code. I definitely don't have a lot of experience though, this is my first iPhone app.
I'm making a data entry field that is comprised of multiple UITextFields within a UIScrollView. I'll avoid explaining the other details for now, as it seems its a very basic problem. Without a scrollview, the textfields work perfectly. I can touch the textfield and the keyboard or picker view show up appropriately. When I add the textfields to a scrollview, the scrollview works, but then the text fields don't receive my touches.
Here's the key: When 'User Interaction' is ENABLED, the scrollview works but the textfield touches are NOT registered. When 'User Interaction' is DISABLED, the scrollview doesn't work, but the textfield touches ARE registered and the keyboard/picker pops up.
From the other posts I have seen people creating subclasses and overriding the touches in a separate implementation. I've seen people using custom content views (subviews?), I've seen some solutions that are now obsolete since the APIs have changed in newer versions of the SDK, and I am just completely stuck.
I will leave out my code for now, because maybe there is a solution that someone has without requiring my code. If someone needs to see my code, I will put it up. My app is being written in the 3.1.3 SDK.
If anyone has ANY information that could help, it would be so greatly appreciated.
Here is what worked for me in Xcode 4.3.3.
In the storyboard, select your scrollview. Select Attribute Inspector on the right side. Uncheck Delays Content Touches.
It sounds like you're using IB to do a lot of your UI layout. If you take a programmatic approach you could set-up the following view hierarchy which should work.
Your view controller object managing your scroll view and your text fields should have a UIScrollView object and a UIView object (in addition to any UITextField objects you need). In the loadView method of the view controller class, allocate and initalize the UIView object and add your text fields to it as subviews. At the end of the method, allocate and initalize the UIScrollView object then add the UIView to the UIScrollView as a subview.
As an example, if your UIScrollView object were called scrollView and your UIView object called mainView the following lines at the end of the view controller's loadView method would properly set up the scroll view with the main view with the text fields on it:
scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = mainView.frame.size;
[scrollView addSubview: mainView];
self.view = scrollView;
You may need to enable / disable user interaction for both the scroll view and text fields as necessary.
If possible you might best using different touch mechanisms for each process (scrolling and textfield input).
Maybe you can check the time differential between touch start and end such that you can detect the difference between a drag (scroll) and a tap (text input).
Having said that if you propagate the touches up from the textfields to the scrollview you should be fine. One thing I use is:
[myObject addTarget:self action:#selector(itemTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
which passes the object touched so you can identify it and act accordingly.