UI scroll View Help - cocoa-touch

Hi i need help with UIScrollView..
i m loading tens views onto my scroll view.. am loading them correctly.. I m Using IBoutlet for showing scroll view.
now the problem is i want my scroll view to reset to nil on disappearing and reappearing of mine view..
I m making its delegate to nil. and releasing mine array in which the images are stored.. To make a scroll view nil that is to delete all the subviews of a scroll view do i have to reinitialize the scroll view..
Sorry for my english.. and please any help or hint will be appreciated.

just remove your scrollview subViews and add subview when you want dont need to reinitialize
NSArray *scrollViewSubViews=[yourScrollView subviews];
for(UIView *view in scrollViewSubViews)
{
[view removeFromSuperview];
}
If you wanna Add a view just
[yourScrollView addSubview:yourimageViews];

Related

Changing view repositions them at (0,0)

I created a simple window with the purpose of being something like a "Wizard" (I know Apple guidelines basically forbid you to, I tried to convince the customer, but whatever.
It is just a simple view with two Custom Views inside, one in the bottom part which contains a "previous" and "next" button, and a bigger view at the top which takes most of the space.
I called the bottom view "NavigationView" and the top one "ContainerView".
I created an array to hold a series of views the user is supposed to navigate through with the "next" and "previous" buttons.
So, here's my code.
- (IBAction) next:(id)sender{
currentViewIndex++;
[self animatePushView:YES];
}
- (IBAction)previous:(id)sender{
currentViewIndex--;
[self animatePushView:NO];
}
- (void) animatePushView:(BOOL)forward{
NSView *nextView = [viewCollection objectAtIndex:currentViewIndex];
for (NSView *subView in [containerView subviews]) {
[subView removeFromSuperview];
}
[containerView addSubview:nextView];
[nextView setFrame:containerView.bounds];
[containerView setNeedsDisplay:YES];
}
It's pretty straightforward I think. I have an array which contains the next view to be displayed.
What happens is that I find the next view centered in the lower left part of the ContainerView. Why does this happen?
Also, as you may have guessed, I'm a newbie at managing views, even though I've been working on objective-c for quite some time, so if there's some best practice I'm missing I'm open to suggestions.
Thanks!
EDIT:
I forgot to add:
Some of these views have different sizes, and I would like to be able to change the window size according to the view size.
[nextView setFrame:containerView.bounds];
You are assigning container view bounds to the next view frame (doc).
What you probably want is assigning the current view frame to the next view frame, and possibly adjust width and height.
Keep a reference to the current displayed view, something like this (_currentView is an ivar of type NSView *) :
- (IBAction) next:(id)sender{
currentViewIndex++;
[self animatePushView:YES];
}
- (IBAction)previous:(id)sender{
currentViewIndex--;
[self animatePushView:NO];
}
- (void) animatePushView:(BOOL)forward{
NSView *nextView = [viewCollection objectAtIndex:currentViewIndex];
[nextView setFrame:_currentView.frame];
[_currentView removeFromSuperview]; // _currentView is retained in the collection
[containerView addSubview:nextView];
_currentView = nextView;
[containerView setNeedsDisplay:YES];
}
Ok, I figured it out.. Finally..
The problem was that the first view I had to show was already contained in the container view in the .xib file.
I don't really know why, but it probably caused some problem with the retain count of the container view, because it was released on the first click.
Releasing the container view would reposition the view on (0,0) probably because its frame was null, and the view would flash because it wasn't retained correctly.
Removing the view from the .xib file and adding it via code works properly anyway.

Update IBOutlet of UIScrollView with new content

I have made a paging using UIScollView. Pages are created 2 and when user scroll it's changes.
Created page is loaded with new content.
Same page have other UIScrollView with UItextView of subviews.
But when i scroll to other page, my UItextViews added to page UIScrollView don't upadtes.
It's updates just then when i scroll that UIScrollview.
Tried this:
for (UIView *childView in _scroller.subviews)
{
[childView setNeedsDisplay];
}
But this not helping
Maybe some one have other suggestions ?
Thanks.

UIScrollView not scrolling in xcode 4?

For some reason UIScrollView is not working. It did work before I add the content but after it stop working. I'm stuck can someone help me out!
Here is my code
This is the code for my UIScrollView
#interface EditAccountViewController : UIViewController {
IBOutlet UIScrollView *svScroller;
}
Here is my view Load code
- (void)viewDidLoad
{
[super viewDidLoad];
[svScroller setScrollEnabled:YES];
[svScroller setContentSize:CGSizeMake(320, 930)];
}
Here is my objects view
View
Scroll View
Image View
View
View
Toolbar
It works also with that.
To my understanding "autolayout" set constraint after loading the view so the problem could be that you set your constrains on viewDidLoad and just after that "autolayout" changes that. Try to set this constrains on viewDidAppear.
Get it from: scrollview xcode4.5 autolayout. Thanks.
Always keep in mind that the content view needs to be larger than the UIScrollView instance frame size. If it isn't, it will not enable scrolling.
This applies to UITableView as well. The scrolling for UITableView will not appear unless there are more rows to be displayed than actually are.
I resolved the issue. I just bump the height in [svScroller setContentSize:CGSizeMake(320, 1500)]; and It's working fine.

How to access subviews in nested UIScrollViews

I was having trouble getting a UIScrollView with multiple UIImageView subviews to zoom properly so I tried using a UIScrollView with multiple UIScrollView subviews inside of it and a UIImageView inside of each of those. That way one UIScrollView can only scroll and the other can only zoom.
My question is: How can I access subviews of a subview. I know that normally I can access subviews using [scrollView viewWithTag:tagInt]; for example, but I can't seem to access the subviews of a subview using [[scrollView viewWithTag:tagInt] viewWithTag:tagInt2]; since viewWithTag only returns a single UIView and not all of it's subviews.
I could always give each subview a unique tag and access them that way, but that doesn't seem to be the most elegant solution.
What is the best way to access a subView and then get to the subView's subview (ie: access my UIScrollView used for zooming which is a subview of my main view, and then access it's subView UIImageView)?
If you don't feel comfortable subclassing for now, you'd have to assign tags to the UIScrollViews containing images. You'd then have to do what the BobC suggested with a little more work.
for (UIView *subview in [myScrollView subviews])
{
//check if the current subview is one of the UIScrollViews
if (subview.tag > 100)
//do something with the UIScrollView
}
The most elegant way to do this would be to subclass UIScrollView, give it a UIImageView property. That way, you could access this UIImageView with something like:
MyScrollView *myScrollView = (MyScrollView *)[scrollView viewWithTag:tagInt];
UIImageView *imageView = myScrollView.imageView;
Hope this helps!
You can get an array of subviews of any UIView using subviews property.
for(UIView *subview in [myScrollView subviews]) {
// do anything with your subview here.
}

stop tableviewcontroller scrolling

I am adding a textview to UITableviewController's view and now I want to stop the scrolling of view of UITableviewController.
But I am unable to do so. As its a view so no enable and disable scrolling properties like table view are existing.
Any ideas???
self.tableView.scrollEnabled = NO;
where self is your UITableViewController