cocoa touch - problem updating subviews! - iphone

I have this UIViewController which contains an UIScrollView.
In the viewDidLoad method of the first controller, I create some UIViewControllers(defined through a NIB with an UILabel and an UIImageView inside,linking to IBOutlets done correctly), then I add them to the UIScrollView.
Problem is, I can see my views and scroll through them using the scroll view, but I seem to be unable to modify the text of the label and the content of the imageView using the methods [[UIViewController UILabel] setText] or [[UIViewController UIImageView] setImage]
I know it sound like a stupid question, but I can't get past it.
Any idea why?
Thank you guys.

You need to tag the Label and ImageView.
tag means assign a integer value to label and ImageView and you can access using the tag.
You can assign tags in xib.
Then you can access the view like this[someController viewWithTag:(int)];

I think I have resolved my problem. I was trying to modify the views before adding them to the UIScrollView.
If I call my methods after the [scrollview addSubView:myView], everything works fine.

Related

Touch detection problems with custom View inside UIView NOT UIScrollView

I was googling for a while and I found similar problems but when the custom View is inside a ScrollView, but that is not my case.
I have a custom view that consists of a UILabel behind a UITextField, so I can animate that label later.
The problem is that when I add a View in my ViewController and in the Identity Inspector I set the Class as my custom class, when I use the application the UITextField within my custom view does not receive the touches well and it takes time to gain focus and therefore to open the keyboard. The strange thing is that if I move that same arrangement of views to my main ViewController in Storyboard everything works fine. Why doesn't it do it when I place it using the described method?
I plans to reuse this custom view a lot, so putting logic and views in each ViewController is not an option.
Thanks in advance
Well, the problem was in the constraints of the container UIView. That means, the UIView in my main ViewController. The Height of the UIView was a little bit smaller than the space required for my custom view, so although my custom view seemed to draw correctly, it was not receiving the gestures correctly. The solution was simply increase the height to the correct value occupied by my custom View. Thanks a lot!

Using UIViewController with a UIView - (Want to use UIScrollView instead) - How to make the switch

I need to implement a scrolling window in order to accommodate all the items on the form I am creating. My current implementation is a UIViewController (that's vcAddCourse) and it has a UIView in it with my current form.
Here is what I have done to add the UIScrollView into the equation.
1) Using IB, I dragged a uiscrollview object 'into' the existing uiview object.
2) Using IB, Ctrl-dragged from file owner to the IBOutlet I created for the new uiscrollview
Here is how I init this controller.
3) I made sure that all the items on my form were now dragged to be under the UIScrollview object.
Finally, over in my .m file, in the ViewdidLoad() function, I added the following line:
theScroller.contentSize=CGSizeMake(328, 680);
No joy. I see the form but it does not scroll.
Note: this on iphone simulator.
What else must I do to swap out the UIView for the new UIScrollView?
Thanks!
To keep things like these clear, I keep the scrollView and the (larger) subview separate in the xib file (as siblings). Your form should be on a UIView, and would be larger than the scrollview. That way you can use IB to layout the form exactly as you want.
To make things work you just have to have the IBOutlets to the UIScrollView and the UIView, and add the view to the scrollview in the viewDidLoad method of your viewController:
[theScroller addSubView:formView];
I'm not exactly sure, but I don't think you have to set the contentSize manually after this, as it should automatically be made big enough to fit your view. If it's not working you might try this:
theScroller.contentSize = formView.frame.size;
Hope this helps

Integrate an UIScrollView to an existing view

I have a View in a xib file and a corresponding ViewController.
With Interface Builder I put an image, some labels and now a table view in it.
What I want to have, is that the whole view will be scrollable, because the new table view is currently only scrolling inside the tableview boundaries.
How can I put a scroll view behind this existing view with IB?
I already put a UIScrollView to the IB and put all other elements on it. Also I create an UIScrollView IBOutlet and connect it, but the screen is not scrollable...
Do I have to do something like
[myScrollView addSubview: ???];
Thank you a lot in advance & Best Regards.
You need to set the contentSize property of the scrollview before it is usable. Yeah, I know - freaking ridiculous that this isn't automatic.
Just do myScrollView.contentSize = CGSizeMake(int, int).

Can't touch UITextField on UIScrollView

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.

Floating a UILabel above OpenFlow

How do you get a UILabel to float above Alex Fajkowski's implementation of CoverFlow called OpenFlow?
Ok I've figured it out. I just had to use bringSubviewToFront with the UILabel.
Thanks to everybody who answered.
Make an OpenFlow instance and a UILabel instance subviews of a parent view, placing the label atop with flow view using -insertSubview:atIndex:, -addSubview: or similar e.g.:
[self.view addSubview:myOpenFlow];
[self.view addSubview:myLabel];
To answer the second question, try this: edit the AFOpenFlowView in IB and add the label view as a subview of that wherever you want it to appear, then set the attributes on the view to Hidden if you don't want it to appear by default. Create an IBOutlet for the label view in your controller so you can easily manipulate it, such as setting hidden to show in order to show it. I'm not familiar with open flow so I'm not sure if it will programmatically create a subview that will obscure your label. If so you may need to use the outlet to move it to the front using UIView methods.
The Openflow example code shows a perfect demonstration of this. Alex adds an info button in the top right of the openflow view using interface builder. This is exactly what you are asking for.
I would add that if you can't understand what is going on from the example code, you should look at more code examples from Apple demonstrating simple UIView usage.
It's not so easy because the label name has to change for each picture. We have to work with index, and with event.. move.. tap.. selected...I'm working on too !