iOS - Navigation Title Not Updating - iphone

What I'm doing with this bit of code is grabbing an image sequence, grabbing it's name. Then setting the view's title as the sequences name playing the sequence then setting the title back to the old title.
Problem is the title doesn't seem to be changing on the navigation bar. The NSLogs are outputting the correct values though.
I remember having this issue before and solving it with some "refresh" method.
Here is the pertinent code.
-(void)playSequence
{
if (([animatorViewController isAnimating] == FALSE) && (btnDisable == FALSE))
{
Sequence *tempSequence;
tempSequence = [fullStepList objectAtIndex:lastPlayedSequence];
self.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
NSLog(self.title);
[self startAnimator:tempSequence.imageNameScheme forNumFrames:tempSequence.numberOfFrames playInReverse:FALSE];
tempSequence = nil;
tempSequence = [fullStepList objectAtIndex:queuedSequence];
self.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
NSLog(self.title);
tempSequence = nil;
}
}
EDIT: This method of changing the title is working else where in this class. The problem seems to come in when trying to set it twice that is causing the issue.
EDIT2: It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.

A navigation item may contains four things: leftBarButtonItem, rightBarButtonItem, title, and titleView. When you need to change the title you should assign your title to navigationItem's title property, not to your view's title property. So it would look like:
self.navigationItem.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
self.title points to your viewControllers title which don't shows up in the navigationBar.

The title won't appear to update until after the main run loop executes. Unless -startAnimator:forNumFrames: invokes the main run loop to execute before it returns, you won't see the change.

If you are hosting the UINavigationController inside another view, you need to do this:
self.yourNavigationController.title = #"title";
instead of
self.title = #"blah"
Otherwise you are just changing the title of the view hosting the view navigator. Just a guess.

I recently found myself in a similar situation. My view's title was comprised of a label with an NSMutableAttributedString. Calling [self reloadInputViews] whenever I updated my title worked for me.

The dreaded P.E.B.K.A.C. error was the cause of this confusion. It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.

Related

FPPopover UITableView return value

i don't know if anyone is using this open source library for replacing UIPopovercontroller for an iPhone.
i'm trying to deploy the FPPopover into my project, everything is working like i want, but the problem is that i'm not able to return any value to my ViewController.
i'm trying this in didSelectRowAtIndexPath
myParentViewController *parentController =(myParentViewController*)self.parentViewController;
but the problem is that self.parentViewController is (null)
i have also another problem, how can i dismiss the FPPopoverController from within didSelectRowAtIndexPath.
I dismissed the view by adding a popoverView property to the table view controller that is popping up (in this case ATableViewController), and then assigning the FPPopoverViewController to that property. Like this:
ATableViewController *aTableViewController = [[ATableViewController alloc] init];
FPPopoverController *aPopoverController = [[FPPopoverController alloc] initWithViewController:aTableViewController];
aPopoverController.delegate = aTableViewController;
aTableViewController.popoverView = aPopoverController;
Then in didSelectRowAtIndexPath of aTableViewController you can just call:
[self.popoverView dismissPopoverAnimated:YES];
If you are trying to return values to the "parent"...since the parentViewController property is null here, you can just make your own property for it (let's call it "parentView"). So when setting up the above you would use:
aTableViewController.parentView = self;
Then you can access any of the properties of the parentView and return values from the aTableViewController that popped up. A bit of a workaround, but that's what I did...hope it helps!

Updating UINavigationBar Title

I have a split view controller and a navigationcontroller on the left side. As views are pushed onto the nav controller I'm attempting to change the Navigation Bar title. The problem seems to be that the text can only be updated in viewWillAppear. If I try to change the text after that initial load, it doesn't update. At first I thought I needed to call setNeedsDisplay on the NavigationItem, but it doesn't have a property. I don't understand because the same code works in viewWillAppear but not once the view is shown.
I'm using:
(void)viewWillAppear:(BOOL)animated{
self.title = #"blah";
...
}
It should be self.navigationItem.title = #"Some Title";
I've set up a simple project where initial controller is embedded in navigation controller, and the second controller is pushed onto the navigation stack. Second controller has a button which calls this bit of code:
- (IBAction)changeTitle:(id)sender {
static unsigned int i = 1;
self.navigationItem.title = [NSString stringWithFormat:#"Number of changes: %ud", i];
i++;
}
It works as intended. Clearly it happens after all appear/layout events. So your problem lies somewhere else. Maybe self that you are referring to is a wrong controller.
self.navigationBar.topItem.title = [NSString stringWithFormat:#"TOP"];

initWith Frame?? CGRectMake - XIB Size is wrong

In my MainControllerClass I have a few XIB's that I am initializing and throwing on the screen - Here is an Example
self.widgetPeopleToBuyFor = [[WidgetAddPeopleToBuyFor alloc] initWithNibName:#"WidgetAddPeopleToBuyFor" bundle:nil andUser:self.currentUser];
self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
self.widgetPeopleToBuyFor.delegate = self;
[self.viewMainView addSubview:self.widgetPeopleToBuyFor.view];
[self.viewMainView bringSubviewToFront:self.widgetPeopleToBuyFor.view];
if ([self.currentUser.wPeopleToBuyForRect length] > 2) {
NSLog(#"LOADING FROM DB");
CGRect rect9 = CGRectFromString(self.currentUser.wPeopleToBuyForRect);
self.widgetPeopleToBuyFor.view.frame = rect9;
}
else
{
NSLog(#"FIRST TIME");
self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
}
I'm building this app so the user can resize the the view to their desire, move it around etc. So when he user Exits I call this method to grab the view information.
- (NSString *) showInfoViewSize: (UIView *) view
{
return NSStringFromCGRect(view.frame);
}
So from there I save the information in the Database, it saves ok - But I just learned the size doesn't matter - I could change it to (10,10,200,200) and the view stays the same exact size on the screen.
So I know I threw a buch at you there. But in the End, the DB works fine - the IF statement gets fired off - Its just I can't resize the XIB on launch.
Should I be resizing it a different way? Should I keep track of the TRANSFORM from the pinch recoginier and just retransform it the scaleFactor at load? Seems kinda hokey to me.
Any help is appreciated - I've been beating myself up on this, and I bet its something super simple I'm missing.
view does not loads from xib until it is presented and hence at that time there will be no frame to set for view. let the view load first then set its frame afterwards.
change the view.frame in "viewWillAppear" in your controller's implementation.
Normally when something is just not working, it's because you've got a nil floating around somewhere you didn't expect. Remember, sending messages to nil is completely legal in ObjC (it just always returns nil).
So I'd step through this in the debugger and check everything to make sure it's a real instance and not nil.
But generally what you're doing (allocing a controller with a nib, setting that controller's view's frame, then adding the controller's view to a superview) is the correct way to do it.

How do i properly discard a subview?

I have a problem with my app where the code for which is far too long to go into, but suffice to say when i'm removing a UIView and replacing it with a new one like so:
NSLog(#" .. %#", (Icon *)[self viewWithTag:index]);
Icon *icon = (Icon *)[self viewWithTag:index];
CGRect frame = icon.frame;
int tag = icon.tag;
[icon removeFromSuperview];
[icon release];
Icon *icon2 = [[Icon alloc] init];
icon2.frame = frame;
[icon2 makeIconStandardWithTag:(int)tag];
[self addSubview:icon2];
It does some weird thing where that NSLog the first time (because the view is already there) shows that the object is an icon, but the second time after running this code shows that it's a UIImageView for some reason now, and it displays what i presume to be the original icon at some odd position on the screen. It's very erratic behaviour. But what i do know is this:
Removing the [icon removeFromSuperview]; line, although keeping the object there, stops this behaviour and causes the NSLog to return an Icon, as it should.
So my guess is that it's not removing icon correctly. Is there a way to completely remove icon, or is removeFromSuperview as far as i can go. What i could do is just have it set to alpha = 0 but this is more of a patch-over solution and not how i want to solve it.
"Is there a way to completely remove
icon, or is removeFromSuperview as far
as i can go"
You can set the object to nil:
icon = nil;
Can you verify what "self" is in this line of code:
It might not be what you think.
[self addSubview:icon2];
NSLog(#" Self is %#", self);
This is a guess, but try setting self.tag to -1 or some other value that doesn't collide with the tags you're setting on your Icon objects. The viewWithTag: method searches the current view and its subviews for a match, so if self.tag == 0 and you call [self viewWithTag:0], you'll get self.
Did you retain icon somewhere prior to this? If not, no need to release it after the call to removeFromSuperview. Similarly, unless you need the reference to icon2 elsewhere, you can release that after calling addSubview.
Views retain views added via addSubview, and they release views removed via removeFromSuperview.

iPhone: Trouble reading badge value from uitabbaritem

I'm trying to figure out programmatically if a particular tab bar item in my app has a badge.
While I'm debugging, visually, I can plainly see that it does. But when I run this code in the viewController in question:
UITabBarItem* thisVCsTabBarItem = self.tabBarItem;
NSString* badgeValue = thisVCsTabBarItem.badgeValue;
...badgeValue is nil. And when I inspect thisVCsTabBarItem in the debugger, its _badgeValue member is nil.
What's going on here? Should I be doing something differently in trying to read this value from the tab bar item?
Thanks.
Looking at some code where I use the UITabBarItem badgeValue property, I see that self.tabBarItem.badgeValue returns nil while self.navigationController.tabBarItem.badgeValue returns the correct value. Could that be it?
The thing is that the auto-completion actually gives me tabBarItem after self. Easy to make a mistake because of that.
I do something like this for a Downloads tab:
for (UITabBarItem* item in self.tabBarController.tabBar.items) {
if (item.tag == 3) {
if (downloadCount > 0) {
item.badgeValue = [NSString stringWithFormat: #"%d", downloadCount];
} else {
item.badgeValue = nil;
}
}
}
I don't think you are supposed to access the tabBarItem directly. It is better find your item in the tabBarController's items array.