Henrik Carlsson's Blog

All things me.

kUTTypeImage is defined in MobileCoreServices.framework

posted this on and tagged it with Narrating my work Objective-C

This gets me every time I try to create a sharing extension for iOS. I follow along with the WWDC session ”Creating Extensions for iOS and OS X, Part 1” from 2014 and when I encounter this line, I get an error:

The problem is that kUTTypeImage is unknown to Xcode. The solution is to import MobileCoreServices.framework.

(For more on this, check out this StackOverflow thread.

Ett svar till Christoffer (@c_vilander)

posted this on and tagged it with Objective-C

Three hours later, trying to figure out how (if even possible) to add a ’Action Segue: Show’ from a cell to a View Controller …

Christoffer Vilander (@c_vilander) on Twitter

Om jag förstår det du försöker göra rätt, och om jag minns rätt vilket inte är någon garanti, så ska du skapa en segue i dina storyboards från din UITableView till vyn som du vill visa. (Ctrl-dra från TableView till målet.) Sen ger din segue en ”identifier”.

Sen har jag inte koll på hur det ska se ut i Swift men i Objective-C så hade jag gjort så här i TableViewController.m:

Hoppas att det var svar på din fråga och att det hjälper.

Replies and comments

Scrolling a UIView to keep the keyboard from obstructing the view of the current UITextField

posted this on and tagged it with iOS Narrating my work Objective-C UIKit

Wow, that’s an unwieldy title!

Anyway, during some spare time today I’ve struggled with something in Objective C and Cocoa Touch that I’ve been struggling with before. When a UITextField in an iOS app becomes ”active”, allowing the user to enter text, almost half of the screen gets covered by the software keyboard. That’s all well and good, but that keyboard is likely to obstruct the view of something, maybe even of the UITextField in question and that’s not good.

To avoid this problem, I the developer am supposed to move or resize (or something) the view. There are multiple questions about this on StackOverflow and multiple answers. After some digging and a lot of trial and error I came up with a solution that differed at least somewhat from all other solutions that I could find. As far as I can tell my solution works and it’s pretty short in terms of code, which I like.

I don’t know, maybe it’s a bad solution. If so, please let me know.

The solution

First, embed all the views that need to move inside a UIScrollView.

In my case I have multiple UITextFields that needs to move so I placed them all inside a UIScrollView. I then added the following property to my ViewController:

This property is updated on textFieldShouldBeginEditing like so:

Then , in my viewDidLoad I added the following two observers:

These will trigger the methods keyboardDidShow and keyboardDidHide when the keyboard appears and disappears respectively. It is in those methods that ”the magic” happens:

Coda

As I said, this works but it’s very possible that it’s a bad solution. If you like the solution, feel free to use it. If you think it’s bad, please tell me so and why so that I can learn and become a better programmer.