WatchOS 3 sharing information and actions between interfaces - watchos-3

I have a table on my main watch interface. Upon user selection, a 2nd interface will show and display more details about the user picked item.
I'm thinking about adding a button to this 2nd interface, so when user clicked on this button, the watch will send the picked item's information to the pair iPhone through WatchConnectivity.
The problem is how can this button-click event on the 2nd interface trigger the WCSession action on the 1st main interface?
Thank you!
Paul

The proper way is to create delegate method in the class you manages WCSession and you would be able to interact using WatchConnectivity at any part of your watchOS app. Do not bound the code that manages WCSession with any interface.

Related

Must a button control be added as a property in the Interface?

I'm new to Objective C and there are a few basic things that I do not yet understand from the tutorials and books I've looked at. For this question I am confused about whether a button needs to be connected to a property in the Interface as well as being connected to the IBAction method.
Seems like a simple question that might help others. Thank you.
You should hook up items in interface builder to IBOutlets only if you need to operate on them in the view controller. For instance, if you wanted to change the button's title text to be localized on load, then you would hook it up. If all you want to do is respond to a specific action on the button (touch up inside for instance), then you only need to hook up the IBAction portion. The short answer is that you are not required to hook up the IBOutlet.

How to make mainMenu send all action to specific NSWindowController?

Short answer is inside the title :)
Explaining: in my MainMenu.xib I have only the Main Menu of the application, that must be same for all NSWindows I open. There is one particular NSWindowController that has, let me say, all answers about when menu item must be enabled (via cases on selector in validateUserInterfaceItem) and what to do with all actions. When NSWindow associated with that NSWindowController is currently focused, there is no problem, but as I focus on another NSWindow all menus are grayed.
I have this flow now: MainMenu is created by reference to it as Main nib into info.plist, then AppDelegate do some init stuff and create MainWinController with MainWindow, at some point MainWinController creates 1+ DetailsWinController with DetailsWindow. AppDelegate manage my custom menu by calling each time functions from MainWinController.
So, how can I force the responder chain to query always that particular NSWindowController (MainWinController)?
You don't give many details to go on, and it isn't clear what you are trying to achieve.
My first reaction is that if you want share Menu items why are you creating multiple windows rather than Views within your MainWindow?
Assuming both your MainWindow and DetailsWindow implement the same selectors you could direct Menu Actions to the First Responder
To add the DetailsWinController in the InterfaceBuilder drag an NSObject from the Object Library, then in Identity Inspector change its class to your DetailsWinController class.
If your Main Menu has different items for the DetailsWindow just connect these to the actions in that instance.
NOTE if you so this you should NOT create the DetailsWinController in code.
If you really want to do this in code you will need to add actions and targets to your menu in code.

How should I do this? (iOS plist editing and updating all controllers)

I am making an app which basically presents data (from plist) to user in table form. I have a lot of controllers and the user basically navigates through these controller to get to an item after which a final detail display is shown.
At that last view, the user can add that to favorites.
The way that I am passing data to view controller is that I pass them specific data, so at the last view, if the user adds the item to favorites, I write that data to file. But how can I tell all my other controller that the data has updated?
This is more of a design problem and I don't know where to go..I have some idea but I want to know what is the standard way of doing this...Thanks.
If you're going to be listening for events within multiple objects, take a look at NSNotificationCenter. You can simply subscribe to listen for notifications then post one once the data is updated.
NSNotificationCenter Class Reference

Getting current selection in objective c using WebKit framework?

Is there any method available in WebKit framework which tells that user has clicked on a particular button of the the web page or user clicked on some link.I want to perform some action when user clicks on a button of a webpage,but i am not able to identify that that user clicked on a button.I searched a lot but i am not able to find such method.Please help!
Set the UI delegate and the policy delegate via [webView setUIDelegate:] and [webView setPolicyDelegate:], and implement the delegate methods explained in Web UI delegate protocol reference and in Web Policy delegate protocol reference.
Look for webView:mouseDidMoveOverElement:modifierFlags: in the UI delegate and webView:decidePolicyForNavigationAction:request:frame:decisionListener: in the policy delegate to achieve what you want to do.

How to connect a button to a method on Mac OS X

I am used to programming for the iPhone. There, I would connect a button to an action, and then a method by creating the method like so: -(IBAction) DoStuff{…}. Then I would make an outlet for the button, and then the actual button in Interface Builder. I would then connect the button to the outlet, and then connect the button to the action by clicking on the circle next to Touch Up Inside and drag it over to File's Owner and select my action.
I am new to programming for the Mac, so I tried to drag from performClick to the file I wanted, but it wouldn't let me make the connection. Do I have to do this programmatically or what? How do I get this button to trigger an action in my code?
The fundamental difference is that iOS controls can have multiple actions for different events, but Mac OS X controls only have one primary action (in some cases, there are others that can be set up programatically).
When you right-click on a button in a Mac nib, performClick: is under Received Actions; it’s not an event. The only entry under Sent Actions is “selector”, which is the only thing you can connect to an action on another object.
Because there is only one “sent event”, you’ll normally just control-drag/right-drag from the control to the target and select the action rather than control-clicking, selecting the event and dragging from that.
It works much the same, but unlike UIKit there is only one signature for actions:
- (IBAction)actionName:(id)sender;
See Communicating with Objects and Target/Action in Interface Builder for more.
I like to Control-Click on the button and then drag to the object that I want to recieve the action. I then select the method of possible choices from the popup menu.