Open text file by tapping a view - ios

I have some basic questions. During launching, my app is looking for text files created in application and adds views that represent these files. Simple. I have information about file name, location etc.
Now I want to open a file by taping on a view. Does someone know the best way to open file? I can set Tag property of a view by adding file path. I can subview the UIView class, but don't know which solution is the best :)
Just how to open the file?

You could use enum and set tag to UIView or UIView subclasses (UIButton), and use switch-case to check if the correct view was tapped.
To manipulate with files use NSFileManager: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

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.

iOS: how to watch when a UIView is added under control of a UIViewController while debugging?

I found a view is somehow added under the control of a view controller, how can I track this process while debugging? My goal is to find where and how this view is created and added so that I could remove it since I don't need this view. Thanks.
You can use the Debug View Hierarchy:
Here you can see al the views, find the one you' re looking for, select it and select Show the Object Inspector:
There you will see the memory address of the object, in my case I've selected a UILabel, then you can add a watch expression on the debug area by right clicking:
Write the address casted to your view element (again, in my case a UILabel):
((UILabel*) 0x14ff9c80)
Finally, you will see something like this:
With this you will be able to get some information of the view you're looking for.
You can create a custom subclass for your self.view in UIViewController and override addSubview and insertSubview:atIndex and put breakpoints there.
All added views then should trigger a breakpoint.

Creating text field in iOS Sharing extension

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.

How to call one xib file from another class,ios

I have googled a lot, but some where I am doing a mistake regarding the xib file. I have four buttons in view controller.xib file. Then when I tap the button one two three, alertinputtypetext has to be dislayed. Its done successfully.
But when i tap the fourth button, I need to display pickerView.xib. But when I am debugging the application, the application sequence is missing and showing the main.m class.
Please help me somebody. Give me hint to proceed further.
"I need to display the another file pickerView.xib" ?.. if pickerView is UIViewController subclass you could show it simply .. if its just a nib file contains a pickerView , you could use loadNibNamed:(NSString *)name owner:(id)owner options:(NSDictionary *)options , but actually you don't need to put it in separate nib file .. xib can hold more than one view inside it , so you could use you original viewController.xib , or what I prefer is to it programmatically without loading it from xib.

Programmatically accessing subviews of UIView added in Interface Builder

I have a nib file where I have a view that contains a background image, a button and another image that covers the full screen (a shadow) that needs to be moved to the front.
On the view, I'm creating child views, and after creating those and adding them using [self addView] I need to move to the front the shadow image.
I'm currently using the tag attribute to find that view, but I'm thinking there's probably a better way, by means of identifying the subviews I add in Interface Builder by some name.
I tries adding a IBOutlet to connect the subview with its parent, but it didn't work (and made no sense, since the subview is already connected to its parent in some way).
The IBOutlets way should work, and is probably the best way to do it. Make sure you made the proper connection in Interface Builder after you declared them in the .h file.
The iPhone does a lazy loading of view controllers. The nib might not have been loaded in initWithCoder or any init method for that matter as Kendall specified.
viewDidLoad is the preferred place to access anything from the nib if you want to access them before the view is displayed.
Hope that helps.
At what point are you trying to access the subviews? If you try within init of a ViewController, the IBOutlets will be nil. The first method you can get at them is probably viewDidLoad.
The reason it does make sense to do things this way is that IBOutlets are just direct pointers to some component, even if they are already subviews of something else. Just saves a lot of hunting.
Using the Tag is a perfectly valid way to locate specific views, so long as you're using the viewWithTag: method. If you're already using tags, there's no need to change to IBOutlets unless you just don't like calling viewWithTag:.

Resources