Resetting the selection cursor in a UITextView - objective-c

I've looked at similarly titled questions, such as :
UITextView disabling text selection
but that wasn't quite what I was trying to achieve.
My app has a UITextView that only requires vertical scrolling. When holding down a touch, the cursor obviously appears at the point of the touch. However, when I change the text of the view, the cursor is always put at the end of the UITextView, which of course scrolls my text all the way to the bottom. I've tried setting the selected range, but even with the editable set to NO, this causes the keyboard to popup. I want my view to be able to display my text and vertically scroll, and to be able to reset its scroll position when I change the text. If I could achieve this and not be able to select, copy, paste, edit, etc. I would be perfectly content.
The last time I tried to deal with this I gave up and ended up using a UILabel, however I need to be able to scroll this time around. Would I be better off putting a UILabel inside a scroll view as a work around? Or perhaps releasing the textView would work, but since I have it hooked as a referencing outlet in IB, I imagine I would have to recreate it programmatically, and I'd like to avoid something so hacky if I can.
I'm at my whit's end with something I've always felt should be simple, so thanks in advance for any and all help!

Related

NSTextField wrong cursor until focused

I am able to set clickable links on NSTextField elements, using NSAttributedString. The text shows correctly (blue coloured, underlined) as soon as the view appears.
However, the cursor shows on hover is the editing (I-Beam) cursor, until first click (anywhere) on the NSTextField. Once it is clicked, when hovering over the "hyperlinked" part of the text, the hand point cursor is shown as expected.
I was able to subclass NSTextField and override resetCursorRects, however, this allows me changing the cursor for the entire NSTextField bound, where I want it to show only when hovering over the hyperlinked parts of the text (Or to use cursorRects, but that seems as an overkill, to iterate on the (already iterated on creation) entire text).
I also tried setting the NSCursor attribute of the attributed string, but that did not solve the issue.
This is not directly supported by NSTextField, I believe. It starts working when you click in the textfield because at that point the field editor for the textfield is created; the field editor is an NSTextView, and that does what you want it to do. So you basically have two choices. You can (1) do the easy thing and use NSTextView instead of NSTextField (is there any particular reason why you can't?), or (2) you can set up the right cursor rects yourself in resetCursorRects by looping through the rects for the character ranges that have the link attribute set, but this means setting up a layout manager and so forth – work that is all done for you if you use NSTextView. A third possibility is to make the textfield's field editor come up right away, before the user clicks – in other words, make the textfield be the first responder. But that only works if you have only one such textfield in your window, and if nothing else in the window ever wants to be the first responder, so it is not a very satisfactory fix, probably.

NSPopUpButton in NSToolbar such annoying

Problem solved!:
Just check the "Unified Title And Toolbar" option of the NSWindow and the 1pixel-down problem goes away!
To change the toolbar height just select the Toolbar Item - Custom View and change size in the Size inspector.
==============================
If you know Xcode 5s layout than you should recognise this:
I want to build it for my own. So I dragged a Toolbar in the Window and added a NSPopUpButton. Then I changed the PopUp Button Cell Style to Radio and turned off the Arrows. So far so good.
The first thing I noticed is that the Toolbars has different heights. Does anybody know how to change this behaviour (without subclassing NSToolbar)?
The second and more annoying thing I noticed is that if I choose an Item from the PopUp Button the Image for the NSMenuItem move 1 pixel down.
EDIT: Xcode NSMenuItems don't move 1pixel down
Any suggestions about that thing?
NSToolbar, sadly, can’t really be subclassed. It’s a poorly-written class that tries to be very “magic,” so it’s not even a subclass of NSView—you can’t control how it draws at all, it creates a private view.
You can set its “sizeMode” but I assume you’ve already done that and found that the number of pixels high isn’t what you want.
The easiest thing to do is just leave space for your widgets at the top of your window (above the document content) and have autolayout position your buttons for you. (I haven’t been able to use a real NSToolbar in years because of its limitations.)
As for the popUp menu being mis-aligned with the button: where the menu draws is basically hard-coded, so if you use a button style that NSPopUpButton doesn't expect then the menu will be offset some.
If you’ve already tried just unchecking the “draws border” flag on a default-style NSPopUpButton (one fresh off the palette), There are two solutions for to try: One is to keep trying different buttonStyles that look correct to your eye until you find one that’s not offset. Two is to leave the buttonStyle do the default for NSPopUpButtons but subclass the buttonCell and have it not draw the border (but still leave room for it).

How do I clear a textfield when dragging and dropping?

I have an NSTextField in my app. I want to be able to drag text into the field from other apps. When this happens, I want my text field to erase anything that's already in it, and then show the text from the drag.
How do I do this? I can't figure out to know the text came from a drag. At the moment it just inserts the text whereever I drop it.
the only way is to subclass it and handle the draggingXYZ methods that are part of any nsview

UTextView autocomplete vs live suggestions iOS

If I turn the autocorrection ON, the words get autocompleted, as if I write "wor", I get "word" before I finish writing. I don't want this to happen because I might be writing "world" or any word different than the autocompleted one.
I set Correction off in the Interface Builder and this problem is solved.
The problem now is that I still need the suggestions that appear in a little popover below the incomplete words.
This two features might be different but I don't know how to activate the suggestions.
How can I solve this?
This can be solved with the use of tableview. Create a tableview with the width as of the width of the textfield and height as you like. Place it just below the textfield. Make it hidden initially. When the user starts typing, fetch the array of data that resembles to the typed text and if any exists then, unhide the table view. On the subsequent typing keep on reloading the tableview sections with animations. You should be accurate on hiding, unhiding and then reloading the data on the tableview. I have implemented such thing before. It is really easy and once you get started with it you find it easy.
In the UITextView TextViewDidChange I created a thread that changed the cursor position. This, off course happens after the text view changes. The change of the cursor position triggers the autocomplete without letting me even see that there had been a suggestion.

editing views in IB that start off the screen

I have some views that start off the screen and then slide in and out at various times. In IB, the x,y positions are off the screen, because that is where I want them to start.
Now, I could just put them anywhere in the x,y space in IB and have the viewController's viewDidLoad method move them off the screen initially.
My question is, since they are currently off the screen in IB, is there an easy way to access and edit them in IB without changing the x,y position of a view first so that it appears on the screen in IB? Because I am editing these views fairly often.
If there isn't, then I'll probably just position them anywhere in the visible space in IB and add some stuff to viewDidLoad to get them out of the way. Or any other suggestions I'd love to hear.
If it's a separate view, just drag it to where you want it, and double click it's name in the objects list as seen in edo42's answer. You could also figure out the final x/y coordinates and set those with your code, and just move the view wherever is convinient.
You click there
and then select your view here