Sorry for the complicated title, but it's hard to explain.
This is the hierarchy I have:
Custom View
Custom View
Push Button
Box
WebView
WebView
The way my code works, is that the 'Box' has a 'setContentView' to one of the 2 WebViews shown above. So basically the Box can have a different WebView at any time.
I have the Push Button, which I want to assign to 'Go Back' on the WebView. But I need this button to 'Go Back' on the WebView which is within the Box.
So whenever the WebViews are switched around, the Push Button should link itself to whichever WebView is in the Box, and visaversa.
Is this even possible?
Thanks in advance everyone!
If you had an IBOutlet for your box (called theBox) defined in whichever custom view your button's action method is in, you can just use this in that action method:
[(WebView *)self.theBox.contentView goBack];
So whenever the WebViews are switched around, the Push Button should
link itself to whichever WebView is in the Box, and visa versa.
Why not use a more conventional arrangement? Make the view controller the button's target, and have the action in the view controller take whatever action is appropriate. In this case, that would be adding the appropriate web view to the box.
Views normally don't know anything about how the application works. They just do what the controller tells them to do.
Related
This is kinda long but I want to give as many details as possible.
I have created a status bar app. One of the things I've done is made it to where there is a "Settings" menu item that if you click on, an NSWindow pops up with 5 different buttons -- these buttons are tied to their own custom NSViewController so that if you click them, the View Controller changes, but the window remains the same, just like any other StatusBar app.
On one of the view controllers is a popup button with several user selectable options. If I add a button to the specific VC (view controller) and link that to an ibaction that pulls the selected index of the popup button, it works just fine (i.e. I select item 2, it logs item 2).
Now here's where things get. . . odd. I've created a submenu that would in theory allow the user to quickly change the selected item of the popup linked to my custom view controller. Think of this submenu as being labeled 1-4 and clicking one of those items would change the index of the popup button, however every time I try this and follow it up with a NSLog to ensure the button has changed, it ALWAYS reads zero, in other words, it NEVER changes.
Here's what I tried.
Just like with every other view controller I've ever used, I create a new object of my view controller (alloc, init), and reference the popup button object that i've created as a property. This compiles just fine, but returns only zero no matter what is selected.
I've tried calling the method that I know works (the button that is on the view controller containing the popup), but again, this returns only zero no matter what is selected.
Any advice would be greatly appreciated.
tl;dr: can't change a popupbutton on a view controller from the app delegate or nsstatusmenu item, it just always returns zero.
EDIT: I have found a work around since I can communicate to my app delegate just fine, I created an int property and set it to zero. From there, whenever my popupbutton on my VC changes, I change the value of the app delegate int property and just ensure that whenever the nib launches, it set's the selected item to the app delegate property. I feel there has to be a more straight forward way to just get the value of the popup and change it from the app delegate.
EDIT 2: Some code as requested. I realized I needed to point the the view controller by using initwithnibname from the app delegate and then load the view. Doing so allows me to pull the first object in the popup button, any subsequent changes are not recognized unless I do so via my test button on the view controller itself. Also, I'm adding values to my popup in my awakefromnib in the view controller.
searches_VC = [[Searches_ViewController alloc] initWithNibName:#"Searches_ViewController" bundle:nil];
[searches_VC loadView];
NSLog(#"Selected Title: %#",[[searches_VC profilePopupOutlet] titleOfSelectedItem]);
I just now figured out how to add a new view when you press a button. For example, in my storyboard, I am using a tabbed controller and in my first viewController i have a button in the top right corner on a navigation bar. and when i press that button, it directs to another view controller. I was wondering how I would be able to write the code for that view controller? I tried creating a new file > objective-c class, but I dont know how to link them together? any help?
If you've made that other controller in the storyboard, you just change the class of that controller to your new class that you made. You do this in the identity inspector.
Use navigation controller to navigate between your view's, You have to make an IBACTION method fot the button. In which you will navigate the view you want by pushviewcontroller.
Please see this link...
How to push viewcontroller ( view controller )?
It implies that which class has to be initialized and what is the nib name of this class. We should not do anything in this block, until you need that your code to be executed before viewDidLoad/viewWillAppear.
Turns out that there is no code necessary to get a button to direct you to another view controller that you set up. You have to declare the button obviously in the #interface part, connect the button with it's code, and then you have to use an action connection from the button to the next view controller you want the button to activate. I have used a modal connection personally, mainly because I'm not sure what a push connection is or what it does... But Ya I figured it out! Hope this helps to any other people who need this!
So I've got this "save" button in my main view controller that I would like to move into a different view controller (WriterViewController). After doing this, my custom view controller class isn't able to respond to any of the button events. Not sure what im doing wrong here but here some screenshots:
Save button is first in my main view controller. I'll be moving it to the view controller to the right (WriterViewController).
As you can see, after moving the button into the intended view controller, the view controller has a custom class set to "WriterViewController".
I then ctrl + click and drag the save button so that i can link up it's "Touch Up Inside" event to the "saveEntry" method.
A screenshot of my WriterViewController.h file.
And the implementation.
Doing the same exact step for the main view controller did work and i was able to log my message. However, it wouldn't work for the custom view controller.
Any thoughts?
Thanks for reading!
Why not just make the save button from scratch for WriterViewController? It's not hard to drag out a UIButton and set it's text to "Save."
Regardless, have you clicked on the button in the scene and viewed the connection's inspector to make sure the connections are what you'd expect? It seems obvious, but sometimes the connections can get all screwed up if you forget to clean them up. (ie. you copy a button over, connections and all, and things don't act as you think they should.)
I've got a problem with creating a modal search view that emulates the behaviour of that of the Weather app. Specifically, there are two animations, that are bothering me and introduce unneeded 0.2 s delays:
When the modal view becomes visible, I give focus to the UISearchDisplayController.searchBar by caling becomeFirstResponder in viewDidAppear. However, the keyboard is not visible, when the modal view has slid in, but needs another 0.2s to slide in after the animation of tehe modal view transition is complete. Moving the call to another callback like viewWillAppear or viewDidLoad did no good, the keyboard won't show up in the first place.
When the user touches cancel, there is another animation taking place, before the delegate's searchDisplayControllerDidEndSearch method is called, expanding the search text field and "melting" away the button. Again, this animation is unneded as the modal view is supposed to transition out when the button is touched.
Additionally, when I dismiss and re-present the same view, not only does the keyboard slide in after the transition, but the cancel button does the same (luckily simultaneously).
I am aware of a similar problem described here: Keyboard Animation Issues When Calling becomeFirstResponder within a Modal View Controller.
However, it seems like the behaviour of the search bar is sligtly differet then that of text field. I could not reproduce the steps described by that author to make the keyboard visible by calling becomeFirstResponder in viewDidLoad.
Regards,
Chris
I think I found your answer. When you add a search bar using the interface builder, you can do it two ways: "Search bar" and "Search bar and Search Display Controller".
I was using the second and was having the very same problem you described. I could only invoke the keyboard (using becomeFirstResponder) on "viewDidAppear". But if you do it adding just the search bar it works. Now I can call becomeFirstResponder on "viewDidLoad" and the keyboard appears together with the view itself.
I means a little more work, but really not much. You have to set your controller to be the delegate of the search bar. I added a list view for the results and made my controller become its delegate and its datasource.
Im looking for some help regarding to put a save like confirmation if some changes where made to a UITextField and UISegmentedControl.
Can I prevent the UINavigationController from pop the view? And then pop based on buttons in a AlertView?
I use the UITextField and UISegmented control to POST data to a webservice.
I perhaps need to use a modalView for this? but wanted first to see if someone have another idea, because I would like to keep navigation clicks down if possible.
Any suggestions for this?
Thanks,
Why not just using a UIAlertView?
EDIT: On second thought, and re-reading your question + comment, I would recommend to use a Modal View with classics OK/Cancel buttons + a UIAlertView(s) for confirmation(s). (UIAlertView "poping" on OK/Cancel is easy to do via UIAlertViewDelegate)
That's what Modal views are for, block UI until some user action has been completed. Like a form. This is how I do all my forms, and how Apple does (just look at the create mail screen for an example, or any form of iOS apps)
Adding a "Magical" action requiring user interaction on the back button of a navigation controller is bad in terms of user experience, if you hit back, you expect the view to pop, nothing else. I would then be surprised if Apple SDK even allows to cancel that event...
You can do what you would like without the need of a modal view.
First, you can use your text field's UITextFieldDelegate to set a flag in your controller when the field content is modified. You can reset this flag when the data is sent out.
Then you could override your UIViewContorller's viewWillDisappear to show an alert to the user in case new data have not been posted at the moment the view is going to disappear and give him the possibility of sending it to the server. This method will be called when you move to a different controller in your navigation UI, and you will not have a chance to "reject" the operation.