I am trying to use HTAutocompleteTextField for iOS. I set the text field using the interface builder. Included the required data source and delegate protocols in my header file, and set the datasource/delegate to self in my controller. However, as soon as I hit either the call to set the delegate or the datasource the app crashes. I've checked the obvious to make sure I didn't have a nil HTAutocompleteTextField. Has anyone experienced this issue?
You need to make sure you set the class of the view in Interface Builder to HTAutocompleteTextField. This can be done in the right hand side panel.
(Above screen shot is a crop from the official Apple docs).
Related
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.
So, in Xcode Swift code, you simply drag a UI component to the text editor and create an IBOutlet like #IBOutlet weak var myLabel:UILabel
My questions are:
I read that IBOutlet resolve to nothing during compile time. It's only a keyword for Xcode itself. I assume Xcode generated some code when I drag the UI. So, where is the code and what does it look like?
Say, if I don't have Xcode, where/how should I write code to connect UI with it's behavior programmatically?
After all, is it possible to write, compile, deploy IOS projects without Xcode?
Thanks,
This related question answers about how to program in Xcode not using its storyboard by configuring Xcode.
True, IBOutlet doesn't do anything. In Objective-C this is defined as a macro and will be replaced by nothing while compiling. There is no special code. Interface Builder on the other hand sees this and allows connections for those properties to be configured. The information which outlet property is connected to which object then is saved in the nib file while compiling. After the system loaded all those objects it steps through the saved connection and sets the outlet properties to the appropriate objects using the regular setValue:forKey: mechanism.
You can see this in action if you implement a custom setter for one of your outlets and set a breakpoint on that.
All this is only necessary to support Interface Builder. If you don't use it you don't need the concept of outlets - you just keep references to the objects you need later after you created them.
The same thing also applies to IBAction. In Objective-C this is again defined to be void via a macro. Interface builder sees them and allows you to make connections there. While the nib files are loaded these are connected by sending the addTarget:action:forControlEvents: message to the control this action is connected to. If you don't use IB you can send this message yourself to make the connection.
I've got a view controller xib file with several views in it. I'm building a wizard-type interface. I'm just doing a simple fade between the views, and I'm already using a navigation controller for the main interface. I'd prefer not to use one for this wizard. Anyway, in the views, each panel has at least a button, some sort of input field (usually a UITextField) and some helper text hard coded in a UILabel.
The problem is that not all the UITextField objects are calling the textFieldDidChange method in the delegate (File's Owner - .m file associated with the xib), but all the UITextField objects ARE calling the textFieldDidBeginEditing method.
Makes no sense to me. I feel like I must be missing something simple in how I set up the screens, but I'll be darned if I can figure it out. Each of the screens all look identical in the property sheets (on the right hand side of Xcode), and everything is wired up correctly in the File's Owner property sheet, both in IBOutlet and IBActions.
Here are some shots of what's going on...
Ideas? Thanks.
Here are links to the screen caps of the vital parts.
(being a new member is making it hard to add all the info I need with screen caps!)
As far as I now, there is no delegate method with the header textFieldDidChange. You have created a method of your own, which is depending on a NSNotification. Make sure all the UITextFields are send the right notification.
There is no such method on a UITextFieldDelegate
You may have confused textViewDidChange, which is a delegate method for a UITextView, but itis passed the UITextView that generated the event, not an NSNotification.
Seems like you want textField:shouldChangeCharactersInRange:replacementString: instead.
This is resolved. I'm a knucklehead. :-)
I was attaching my own notifier/observer and hadn't done so for the last few UITextField objects. Sorry to bother y'all.
I'd like to add some custom buttons to an ABUnknownPersonView. Can I use initWithNibName:bundle: in my ABUnknownPersonViewController to load a custom view that I've created in IB, while not using an "undocumented api?" And if I do, how can I make sure that it follows all the properties and responds to all the hooks that the controller expects?
I typically create all my views programmatically and I generally like the view that ABUnknownPersonViewController creates. I'd rather just start from there. And so I accessed the view and dropped in a button, but with later versions of iOS that broke since that isn't a hook that Apple created.
initWithNibName is also not mentioned in the ABUnknownPersonViewController documentation but it is a method of it's parent class UIViewController. Does that make it safe to use?
You cannot provide a replacement XIB. While I understand you want to avoid it, you will have to use the underlying AddressBook framework and building your own version out of it.
You can, of course, look at open source stuff such as this for a good starting point.
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:.