Creating text field in iOS Sharing extension - ios

I'm working on a sharing extension in iOS with Swift. In the share app, I would like to add a custom field, where the user can add text to it. I tried finding references to see how it could be done but I can't find any.
Can someone help me out please?

You can't magically make a text field appear in the SLComposeServiceViewController interface. So you have two choices:
Use SLComposeServiceViewController, and add a configuration item (SLComposeSheetConfigurationItem) which you've set up so that it pushes some new interface containing a text field.
The pushed interface is up to you, even though the SLComposeServiceViewController interface is not.
Don't use SLComposeServiceViewController in the first place. Now the whole interface is up to you. Just use a normal view controller and it will be presented for you, and you can design the view in the storyboard just like always.

Related

Can we access the objects in Storyboard by ObjectID

I have a bunch of static objects (UILabel, buttons, views) in multiple Scenes. They are not connected to any IBOutlet. But I'd like to access them at appdelegate (or first VC), and change their properties before it is loaded.
Anyway to do this?
EDIT: Adding my intention:
I actually wanted to make a custom "multi-language" app. I want to be able to change language from within the app. I can get a list of all the objects by applying built in localization of storyboard (Main.strings is autogenerated). Then I disable localization again. Then from this autogenerated file, I want to be able to connect it to a json data based on language that I select.
Of course you can. For example, you can use tags of UIView. Just set tags in Storyboard. It's easy but not so good. Another way to do this is using Accessibilities. Enable and set for it in Storyboard.
And then you can access it by accessibilityIdentifier property.
I will post my choice of "solution". So what I did was make use of accessibilityIdentifier to set the "key" for the multilanguage phrase translation purpose.
And I make use of the UIView+Recursion class (you can find this simple class somewhere in SO), and basically iterate all the objects in a particular Scene and if the text matches, set the key in accessibilityIdentifier property (either in viewDidload or viewWillAppear or viewDidlayoutSubviews).
This way you can have language changes "on-the-fly" within the app, without restarting.

reloadRootControllersWithNames:contexts: does not load new InterfaceControllers

I have my WatchKit app (WatchOS1) set up in the following way (names have been changed to be project unspecific):
InitialInterfaceController - The main entry point of the watch app. This controller is only used to load several instances (using the same identifier repeatedly in the NSArray) of the next view using reloadRootControllersWithNames:contexts: (called from awakeWithContext:).
FirstInterfaceController - This Interface controller should be what is first displayed for the pages.
However this does not work - I get left with the blank InitialInterfaceController screen. If however I call [self presentControllerWithNames:contexts:] it works as expected, but includes the cancel button, which is not what I want.
I have seen people suggesting to use this method to dynamically create multiple page navigation scenes, but I cannot see why this doesn't work. The FirstInterfaceController's awakeWithContext: is never called.
Has anybody had this problem or is there a fix available?
Do you have the right value for the Identity in the interface controller's attribute inspector? (I have seen issues when the identity and class name are the same, make sure they are different)
Is that interface controller added to the right module in the identity inspector?

How to replace content ViewController inside other View controller

I am working on an application which allows users to work with a couple of workmodes. Main view of the app contains information common to all workmodes. I want to create a "subview" with ability to change its ViewController. This subview will be used to display information connected with specified workmode. It is important that app goes to MainViewController from WorkmodesViewController in which user chooses workmode to work with.
My question is:
Which tehnique should I use to acheave changeable WorkmodeViewController inside MainViewVontroller
I have found example git project with functionality I need:
https://github.com/mluton/EmbeddedSwapping

iOS Interface Builder: How to make templates

I've recently started developing an iOS app, which I've never done before, so it's been going a bit slow, but I'm learning, so that's understandable.
I want to make a custom interface, so I've been making subclasses of the default view classes (like UIButton) so that I can define custom drawing. I've been told this is the best way to define custom interface elements that can be reusable. It definitely seems to be working that way. However, I haven't been able to make elements completely reusable by just using a subclass.
For example, in order to prevent a button's text from changing color when it is clicked, I have to manually go into the interface builder and set the button type to "Custom." After that, code that I enter into the subclass's constructor to change attributes seems to work. But I have to do this for every button I add, and in code the "buttonType" attribute is read only. Is there a way for me to define (just once) certain attributes for every instance of my button subclass that I add to the interface?
My goal is to be able to have a button subclass or template that defines all attribute values that I want my buttons to have, and every instance that I add automatically reflects those properties without me having to change anything. More so, I want to be able to modify that subclass/template and have those changes reflected in every existing instance. I have to imagine that this is possible in iOS. There is simply no way to build sophisticated interfaces without this capability.
Define a custom Button class (inherited from UIButton) in your project and in the init set the properties which you wanted to be set across.
In the interface builder go to the the class inspector and enter the button to be of the previously declared button.
buttonType needs to be set for all the button as this is defined at initialization time and exposed as read only property. If you want absolute reusability for your case, create a view, with an embedded button in code. when you create a button, create using the static method buttonWithType.
Wherever you need, drag and drop a UIView and set the view type to be the custom view.

switch function to make page available

I've searched through the forums and wasn't able to find anything similar to this question. It's my first time posting so please let me know if I need to add anymore information and I'll try my best!
I'm exploring Xcode and building an app for iOS 7 on an iPhone. I'm using a hypothetical purpose for the app just to see if I can learn how to build the thing (it's a booking system for taxis). It's a tabbed application (I have three tabs at the bottom corresponding to three different screens of the app, one is rates which displays a scrollable image of rates, one is a booking system that sends an email with information taken from text fields, and one is a settings page)
My questions is as follows:
On the booking page, I'd like to have a switch that either enables or disables user entry into additional text fields (it's actually for the option to book a 'return' journey, so the user can add in extra information for the return booking).
I have my page set up with the first text fields in place, but I can't for the life of me figure out or find anywhere about how to make this switch enable entry into the additional text fields. Ideally I'd like them to be greyed out and disabled if the switch is off, and enabled if the switch is on.
Any help on the matter would be much appreciated!
Thanks.
edit:I'm also doing this with storyboard, wasn't sure if this made a difference!
You can use UISwitch and UITextField for this. UITextField has a property called enabled that controls whether the user can interact with it.
First you need to create an IBOutlet for your UITextField in storyboard by control-dragging it to respective #interface definition in your header file. Then you need to create an IBAction for your UISwitch, again by control-dragging it to #interface (choosing 'Action' for 'Connection' and 'changed' for 'Event').
Finally implement the newly generated method like this:
#implementation ViewController
-(void)mySwitchChanged:(id)sender
{
UISwitch *mySwitch=(UISwitch *)sender;
myTextField.enabled=[mySwitch isOn];
}
.
.

Resources