When I add some icons (50) to the TTLauncherView Three20 view, TTLauncherView is always in the last page of the pages of icons. How can I change it to always show the first page of icons instead of the last one?
Thanks.
Update
in the viewDidLoad method, I call this one:
- (void)loadIcons
{
int first=0;
TTLauncherItem *firstIcon;
for (NSString *nombre in nombres) {
TTLauncherItem *icono=[self generarIcono:nombre];
[launcherView addItem:icono animated:YES];
if(first==0)
firstIcon=icono;
first=1;
}
[self.view addSubview:launcherView];
if (firstIcon!=nil) {
[launcherView scrollToItem:firstIcon animated:NO];
}
}
After adding your icons juste call [launcherView scrollToItem:item1 animated:NO]
You are adding all the items animated. I don't think that is what you want during viewDidLoad and on the other hand, this is what keeps your code from working like you expected. You are adding items animated and then request an immediate (not animated) move to the fist items. That clashes. The simplest thing to do is to add the items without animation [launcherView addItem:icono animated:NO];
But that is not the way you would normally add a lot of items to the launcher. It creates a lot of overhead. There's a pages property, that is better suited for your needs. Look a the TTCatalog example app for code.
Related
Does anyone know of any good tutorials for the following please?
Im new to Xcode and dont know where to start with this.
I have a ViewController that is the root View and has 6 navigation buttons (UIButton) on it. Depending on which button that is clicked, the user will see a sub-navigation View of that section with further button options on it.
So e.g top level will have buttons Where to Eat, What to Do...
Then clicking on Where to Eat will show Restaurants, Fast Food ....etc
I would like to do this programatically. I can do it using Storyboards and using multiple views, but it gets very messy as there are a lot of views on the screen eventually.
I have followed a tutorial HERE on how it is done for TableViewControllers, but I need something similar for buttons.
Im not sure what this function is called - have been searching for sub-navigation for the last while but nothing matches what I need to accomplish this.
Check out UIViewController's method presentViewController:animated:completion: method. It is available in iOS 5.0 and up. Let's say you have one of the button's linked to run the buttonOneActivated: method:
-(IBAction)buttonOneActivated:(id)sender
{
UISubViewController *subViewController = [[UISubViewController alloc] init];
[self presentViewController:subViewController
animated:YES
completion:NULL];
}
And in UISubViewController's implementation, let's say you have another button in order to return to the parent:
-(IBAction)returnToParent:(id)sender
{
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:NULL];
}
When I add a new TTLauncherItem icon to a TTLauncherView, this icon is set at the last position. Could I set it in another position? How should I do it?
Subclass TTLauncherView and override...
- (void)addItem:(TTLauncherItem*)item animated:(BOOL)animated;
If you look at that method in TTLauncherView, you can see how it's getting the page to add to by using...
NSMutableArray* page = [self pageWithFreeSpace:self.currentPageIndex];
So instead of doing that you can pick the first page or whatever. Once you have the page you want to add to you can put the item wherever you want. Page is just an NSMutableArray of TTLauncherItems.
My application is loading a first view (used to login into a Web service). When the login is successful, it performs a CATransition (basic kCATransitionFromRight) to show a second view and hides the first view. I've set the delegate of the transition to self so I can use -(void)animationDidStop:(CATransition *)theAnimation finished:(BOOL)flag.
When that method is called (right after the transition is over) I want to release the first view since I won't need it anymore. However, when I call [firstView release] (in animationDidStop:) the retain count doesn't seem to change. I used [loginView retainCount] to check this and since I know it's not always reliable I was wondering: am I doing this right?
Thank you.
taken from the book "Cocoa Touch for iPhone OS 3" is a similar approach.
They set up an animation remove the old subview, add the new one and then commit the animation.
Jilouc in his comment is right, forget to check "retaincount"...
if you want to be sure that your object view firstView just add a
NSLog(#"i'm removing myFirstView");
in its
-(void)dealloc{
}
method...
if you get that NSLog in debugger console window then be sure you had it removed/released in the right way...
btw... the right way could be something like this:
in animationDidStop:
if (firstView!=nil){
[firstView.view removeFromSuperview];
[firstView release];
firstView=nil;
}
I have an app with a table view at the root in a navigation controller, and on selection of a table cell it displays a new view controller that contains only a UIWebView (with a toolbar and a navbar).
Depending on how I present the new web view, the feature where the user can tap on the status bar at the top and have the webview scroll to the top, either works or doesn't work.
If I use:
(void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
on the RootView, then the webview does scroll to the top.
If I change that one line of code and instead use:
(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
on the navigation controller, then the scrollsToTop feature stops working.
What I really want to use however, for other reasons in the context of the app, is the pushViewController method. BUT, I also want to keep the scrollsToTop behaviour.
I have so far tried various approaches, some described here:
-Attempting to set the webview internal scrollView scrollsToTop property
((UIScrollView *)[[webView valueForKey:#"_internal"] valueForKey:#"scroller"]).scrollsToTop = YES;
(No discernible effect).
-Changing the ordering of setting NavBar properties or not setting any at all
-Adding extra "window makeKeyAndOrderFront" calls after the new view push.
I don't believe there are other views there that could be claiming the "scrollsToTop" property (and the first test above proves that in any case).
Short of attempting to embed UIWebView into a UIScrollView, which I expect will be painful, I have run out of routes to explore to resolve this issue.
I am hoping someone else has found a way to correct this?
Try the reverse approach as a workaround.
In the root view controller:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.tableView.scrollsToTop = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.scrollsToTop = YES;
}
Bye!
It turns out that it wasn't working because of the way I was customiing the Navbar. I was overriding leftBarButtonItem with a UIBarButtonItem that then took up the whole navbar (I think I took that approach from some Apple code many months ago, but not sure). I was using the same approach on another view and the scrollsToTop worked fine there.
Taking that code out and putting the custom Navbar view into (eg)self.navigationController.titleView instead solved this problem. I do not really know why, like I say it works fine for other views.
I wasted a lot of time with this problem, so I hope I save someone else some hair by describing it here :)
I know how to add a UIToolbar, which I'm doing in rootviewcontroller.m:
[self.navigationController.view addSubview:toolbar];
However, when I navigate to other views, the toolbar stays up, which is ok, but how do I access it to hide/show it?
Inside rootviewcontroller I would use this:
toolbar.hidden = NO;
But I can't seem to find a way to do this outside of rootviewcontroller.m
Can you please show me an example of hiding it from another class?
There are two options;
1) Add a property to your controller so external classes can access to the toolbar object.
2) Add a function to your root view controller that can be used to toddle the toolbar.
I would recommend #2 since it restricts what external classes can do.
E.g.
-(void) hideToolbar:(BOOL)hidden
{
toolbar.hidden = hidden;
}
The problem is that you shouldn't be adding it to self.navigationController.view; you should be adding it to self.view. Correcting that should fix it for you.
You could try adding the following line during the initialisation of the View Controllers for which you don't want the bar to appear.
[self.navigationController setToolbarHidden:YES animated:NO];
F.
Andrew Grant's answer is what you're looking for. However, you should rename the method to
-(void) isToolbarHidden:(BOOL)hidden {
toolbar.hidden = hidden;
}
It makes more sense that way when looking at the code.