Questions tagged [cocoa-touch]

The Cocoa Touch Frameworks that drive iOS apps share many proven patterns found on the Mac, but were built with a special focus on touch-based interfaces and optimization.

Cocoa Touch is Apple's application-development framework for , consisting of Foundation, UIKit (), and Core Data ().

The Cocoa Touch frameworks that drive apps share many proven patterns found on the , but were built with a special focus on touch-based interfaces and optimization.

For development, see .

For Cocoapods, see .

Many Cocoa Touch questions deal with , , , or .

Debugging techniques

Cocoa programs can be debugged with many techniques and tools, both general and specific to , , , and .

Apple's Technical Note about debugging iOS applications

34585 questions
306
votes
23 answers

What is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly?

I have a UITableView running under iOS 8 and I'm using automatic cell heights from constraints in a storyboard. One of my cells contains a single UITextView and I need it to contract and expand based on user input - tap to shrink/expand the…
Rog
  • 17,070
  • 9
  • 50
  • 73
301
votes
23 answers

How do you load custom UITableViewCells from Xib files?

The question is simple: How do you load custom UITableViewCell from Xib files? Doing so allows you to use Interface Builder to design your cells. The answer apparently is not simple due to memory managment issues. This thread mentions the issue and…
DrGary
  • 3,321
  • 3
  • 20
  • 14
298
votes
36 answers

EXC_BAD_ACCESS signal received

When deploying the application to the device, the program will quit after a few cycles with the following error: Program received signal: "EXC_BAD_ACCESS". The program runs without any issue on the iPhone simulator, it will also debug and run as…
Héctor Ramos
  • 9,239
  • 6
  • 36
  • 39
298
votes
21 answers

How do I change the font size of a UILabel in Swift?

label.font.pointSize is read-only, so I'm not sure how to change it.
Jay
  • 9,314
  • 7
  • 33
  • 40
297
votes
10 answers

How can we programmatically detect which iOS version is device running on?

I want to check if the user is running the app on iOS less than 5.0 and display a label in the app. How do I detect which iOS is running on user's device programmatically? Thanks!
meetpd
  • 9,150
  • 21
  • 71
  • 119
293
votes
24 answers

Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar

I'd love to create a "back" left-arrow-bezel button in a UIToolbar. As far as I can tell, the only way to get one of these is to leave UINavigationController at default settings and it uses one for the left bar item. But there's no way I can find to…
Marco
  • 14,977
  • 7
  • 36
  • 33
292
votes
8 answers

When is layoutSubviews called?

I have a custom view that's not getting layoutSubview messages during animation. I have a view that fills the screen. It has a custom subview at the bottom of the screen that correctly resizes in Interface Builder if I change the height of the nav…
Steve Weller
  • 4,599
  • 4
  • 23
  • 30
292
votes
15 answers

Clearing NSUserDefaults

I'm using +[NSUserDefaults standardUserDefaults] to store application settings. This consists of roughly a dozen string values. Is it possible to delete these values permanently instead of just setting them to a default value?
TonyNeallon
  • 6,607
  • 12
  • 42
  • 49
291
votes
24 answers

Proper way to exit iPhone application?

I am programming an iPhone app, and I need to force it to exit due to certain user actions. After cleaning up memory the app allocated, what's the appropriate method to call to terminate the application?
user21293
  • 6,439
  • 11
  • 44
  • 57
281
votes
14 answers

Cocoa Touch: How To Change UIView's Border Color And Thickness?

I saw in the inspector that I can change the background color, but I'd like to also change the border color and thickness, is this possible?
Shai UI
  • 50,568
  • 73
  • 204
  • 309
279
votes
39 answers

Hide separator line on one UITableViewCell

I'm customizing a UITableView. I want to hide the line separating on the last cell ... can i do this? I know I can do tableView.separatorStyle = UITableViewCellStyle.None but that would affect all the cells of the tableView. I want it to only affect…
Safari
  • 11,437
  • 24
  • 91
  • 191
268
votes
5 answers

How do you add an in-app purchase to an iOS application?

How do you add an in-app purchase to an iOS app? What are all the details and is there any sample code? This is meant to be a catch-all of sorts for how to add in-app purchases to iOS apps
Jojodmo
  • 23,357
  • 13
  • 65
  • 107
261
votes
46 answers

"Unknown class in Interface Builder file" error at runtime

Even though Interface Builder is aware of a MyClass, I get an error when starting the application. This happens when MyClass is part of a library, and does not happen if I compile the class directly in the application target.
jhoule
  • 2,466
  • 3
  • 17
  • 12
259
votes
7 answers

How to copy text to clipboard/pasteboard with Swift

I'm looking for a clean example of how to copy text to iOS clipboard that can then be used/pasted in other apps. The benefit of this function is that the text can be copied quickly, without the standard text highlighting functions of the traditional…
Garry Law
  • 2,936
  • 2
  • 16
  • 14
257
votes
10 answers

Prevent segue in prepareForSegue method?

Is it possible to cancel a segue in the prepareForSegue: method? I want to perform some check before the segue, and if the condition is not true (in this case, if some UITextField is empty), display an error message instead of performing the segue.
Shmidt
  • 16,436
  • 18
  • 88
  • 136