Edit the toobarItems of topViewController - iphone

I want to change dinamycally the ToolbarItems of my topviewcontroller.
I have a class that does my business logic and as a result returns an array of uibarbuttonitem.
so, i get the reference of the topviewcontroller like this:
ViewController *topVC = [appDelegate.navController topViewController];
now if i try to do:
[topVc setToolbarItems: myArrayofUibarbuttonItems];
But nothing happens.
What I'm missing?

Guess you could do it with the setItems function
[topVc.toolbar setItems:theArray];
just typed, not tested

[topVc.navigationController setToolbarItems:myArrayofUibarbuttonItems];
this should help u.. happy coding :)

Related

How do I save values from a UITextField in the FlipsideViewController and use them in the MainViewController?

SEE EDIT AT BOTTOM
I am making a UtilityView application for the iPhone and I want to be able to change values from the FlipsideViewController. I have a problem that whenever I switch back to the MainView from the FlipsideView, the values of the text fields that I had changed in the FlipsideView are seemingly reset to 0. In the MainViewController.m, under the flipsideViewControllerDidFinish:
playToInt = [controller.playTo.text intValue];
computerMoveSpeed = [controller.aiSpeed.text intValue];
The text field 'playTo' coordinates with the integer 'playToInt' and the text field 'aiSpeed' coordinates with the integer 'computerMoveSpeed'. I think this should save the values, even when the ViewDidLoad runs again, but they both seem to be reset to 0.
if (playToInt != 10 || computerMoveSpeed != 3)
{
playBool = true;
}
else
{
playBool = false;
}
I know that the boolean is working because I can change the integers' values with it, but they always default back to 0. Any help is appreciated. Thanks in advance.
NOTE: I have consulted the previous question 'Passing UISegmentedControl values from FlipSideViewController in an Utility application to the mainviewcontroller…' and that does not work for me... I am have too many possible values to use an index or a switch.
EDIT: I am trying something that I think is really close to working... I feel like it just has bad syntax or something... I have in the MainViewController.m:
computerMoveSpeed = [FlipsideViewController.aiSpeed.text intValue];
playToInt = [FlipsideViewController.playTo.text];
EDIT: I have something that is similar to the last one but I think it will have a better chance of working with some help...
in the FlipsideViewController.m I have
_playToNumber = [_playTo.text intValue];
and in the MainViewController.m
playToInt = [controller.playToNumber];
Any help is greatly appreciated, but as some additional info, on the string in the MainViewController it says it needs an identifier on the playToNumber variable, but it is declared as int... I don't know if there is an identifier for ints but if there is, please let me know!
EDIT: Is there any way to save the values in a usable format for the MainViewController using the prepareForSegue function in the FlipsideViewController?
EDIT: I figured out that it was just getting the initial values when it loaded the ViewDidLoad, so I started using a timer to retrieve the values. This seems to be working, I just need to know how to access these values from the MainViewController?
Use delegate to send values back to MainViewController. See this tutorial to learn how to use delegates.
You have many way to do this task,
1. NSUserDefault
Follow ma answer Link
2. Using Getters, setters, property
Follow ma answer Link
EDIT
If you want int or NSInteger then no need for retain
just do
#property(nonatomic) NSInteger YourIntValue;
and
_playToNumber = [_playTo.text intValue];
MainViewController *MVC = [[MainViewController alloc] init];
MVC.playToInt=_playToNumber;
[self.navigationController pushViewController:MVC animated:YES];

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!

If labels are equal change view

hi I got this code and when I hit button a lot of things happen, images get set etc. But I also want it to compare 2 labels and when They are equal I want it to change view. It doesn't work can someone have a look why?
-(IBAction)play {
if (labelsText.text == textview.text){
GoedwoordViewController *Goedwoord = [[GoedwoordViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Goedwoord animated:YES];
}
labelsText is my input label, textview is a label in which a random word will appear.
GoedwoordViewController is the destination view. and GameViewController is the current view.
hope someone knows
Change Following line...
if ([labelsText.text isEqualToString textview.text])
Hope, this will help you..
When you do:
if(someString==anotherString){}
You're checking if the pointer of someString is the same of anotherString, so never use == to compare strings.
The best is to use the #Nit solution that check if the strings are equals.

Pass Data Between Two UIViewControllers

I need to pass data of UILabel from ViewB to ViewA. My ViewA has a UILabel with some number. This number can be changed in ViewB which I open as a new UIViewController as below:
viewB = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
ViewB also has a UILabel to hold the same value. I tried to pass this value from ViewB to ViewA by assigning UILabel's like so:
viewB.countdownLabel = self.countdownLabel;
That didn't work. Thanks for suggestions...
i think what you want is:
viewB.countdownLabel.text = self.countdownLabel.text
Make sure viewB.countdownLabel is a retain property and it should work.
By saying "viewB.countdownLabel = self.countdownLabel;" you are simply making viewB's countdownLabel a reference to the original label, you're not copying their values. You need to do the following...
[viewB.countdownLabel setText:self.countdownLabel];
I would suggest that you use AppDelegate to pass the value across to any viewController (and read the documentation here).
GeneralAppDelegate*appDelegate=[[UIApplication sharedApplicaton] delegate];
myLocalProperty=appDelegate.someDataModelProperty;
or just use
viewB.countdownLabel.text = self.countdownLabel.text;
in your code.
KVO also can be used.
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177-BCICJDHA

how to send string value with popToViewController

I am using navigationcontroller. i have (Root,A,B,C,D) class. i want to sand a string test value Class D to Class A via popToViewController.
Please give me suggestion.
Thanks
UINavigationController maintain the list of all pushed controller in viewControllers and the root controller always reside at 0.
MyAController *myController = (MyAController *)[self.navigationController.viewControllers objectAtIndex:0];
myController.myText = #"My String" ;
[self.navigationController popToViewController:myController animated:YES];
You might want to rethink your design, but since you haven't given enough information for me to suggest how, you could just try this:
A *aController = (A *)[myNavController rootViewController];
[aController setMyString:#"your string here"];
[myNavController popToRootViewControllerAnimated:YES];
Make that string as property of class a then you need to access that object of the view A from navigation stack in class D.
And then access that property for using.
If Class A is rootView then jtbandes answers helps you otherwise pick it up from stack code some thing like this
if([self.navigationController.viewControllers count]>3)
A *aController=(A *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-4];
if your navigation is A->B->c->D
then you can access c by [self.navigationController.viewControllers count]-2 similarly B by -3 A by -4.
There are several approaches to achieve this.
Using Notifications.
Using Delegates.
Using Outlets/Properties.
You could also create a ControllerA instance var in your ControllerB and then pass the ControllerA (self) to ControllerB(ex: by a method) before call pushViewController from A to B. You can do the same from B to C...etc; i think the best solution is that of Jhaliya in case you want to work with navigationControllers.