ios interview questions
Top ios frequently asked interview questions
I have UTF-8 encoded NSData
from windows server and I want to convert it to NSString
for iPhone. Since data contains characters (like a degree symbol) which have different values on both platforms, how do I convert data to string?
Source: (StackOverflow)
I'm updating an old app with an AdBannerView
and when there is no ad, it slides off screen. When there is an ad it slides on screen. Basic stuff.
Old style, I set the frame in an animation block.
New style, I have a IBOutlet
to the constraint which determines the Y position, in this case it's distance from the bottom of the superview, and modify the constant.
- (void)moveBannerOffScreen {
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = -32;
}];
bannerIsVisible = FALSE;
}
- (void)moveBannerOnScreen {
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = 0;
}];
bannerIsVisible = TRUE;
}
And the banner moves, exactly as expected, but no animation.
UPDATE: I re-watched WWDC12 video "Best Practices for Mastering Auto Layout" which covers animation. It discusses how to update constraints using CoreAnimation
.

I've tried with the following code, but get the exact same results.
- (void)moveBannerOffScreen {
_addBannerDistanceFromBottomConstraint.constant = -32;
[UIView animateWithDuration:2
animations:^{
[self.view setNeedsLayout];
}];
bannerIsVisible = FALSE;
}
- (void)moveBannerOnScreen {
_addBannerDistanceFromBottomConstraint.constant = 0;
[UIView animateWithDuration:2
animations:^{
[self.view setNeedsLayout];
}];
bannerIsVisible = TRUE;
}
On a side note, I have checked numerous times and this is being executed on the main thread.
Source: (StackOverflow)
I have a UILabel
with space for two lines of text. Sometimes, when the text is too short, this text is displayed in the vertical center of the label.
How do I vertically align the text to always be at the top of the UILabel
?

Source: (StackOverflow)
This question relates to iOS pre-3.2. As of 3.2 this functionality is easily achievable using samvermette's answer below, and I have changed the Accepted Answer (from commanda to samvermette) to reflect this. I can't give credit to both answers (besides uproots) but they are both good.
I would like to have an app include a custom font for rendering text, load it, and then use it with standard UIKit
elements like UILabel
. Is this possible?
I found these links:
but these would require me to render each glyph myself, which is a bit too much like hard work, especially for multi-line text.
I've also found posts that say straight out that it's not possible, but without justification, so I'm looking for a definitive answer.
EDIT - failed -[UIFont fontWithName:size:]
experiment
I downloaded Harrowprint.tff (downloaded from here) and added it to my Resources directory and to the project. I then tried this code:
UIFont* font = [UIFont fontWithName:@"Harrowprint" size:20];
which resulted in an exception being thrown. Looking at the TTF file in Finder confirmed that the font name was Harrowprint.
EDIT - there have been a number of replies so far which tell me to read the documentation on X or Y. I've experimented extensively with all of these, and got nowhere. In one case, X turned out to be relevant only on OS X, not on iPhone. Consequently I am setting a bounty for this question, and I will award the bounty to the first person who provides an answer (using only documented APIs) who responds with sufficient information to get this working on the device. Working on the simulator too would be a bonus.
EDIT - It appears that the bounty auto-awards to the answer with the highest number of votes. Interesting. No one actually provided an answer that solved the question as asked - the solution that involves coding your own UILabel
subclass doesn't support word-wrap, which is an essential feature for me - though I guess I could extend it to do so.
Source: (StackOverflow)
My application has a dark background, but in iOS 7 the status bar became transparent. So I can't see anything there, only the green battery indicator in the corner. How can I change the status bar text color to white like it is on the home screen?
Source: (StackOverflow)
This question already has an answer here:
There are a lot of questions about this problem on SO:
But really no one answer works for me.
How do I capture an image programmatically without the camera shutter sound activating?
Source: (StackOverflow)
I have an app that I developed with XCode 3 and recently started editing with XCode 4. In the target summary I have the iOS application target form with fields: identifier, version, build, devices, and deployment target. The version field is blank and the build field is 3.4.0 (which matches the version of the app from when I was still editing with XCode 3).
My questions are:
What is the difference between the version and build fields?
Why was the version field blank after I upgraded to XCode 4?
Thanks.
Source: (StackOverflow)
I've been developing an app for 1 or 2 weeks now and just yesterday I've updated my iPhone 5S to the iOS 8 GM. Everything worked fine and I could test on my device as well until I deleted the app from my phone and wanted to build again. The following error appeared:
Could not launch "My App"
process launch failed: Security
When I test with the simulator it works fine.
Is this because of the iOS 8 GM update and how can I fix this launch problem?
I want to be able to test on my iPhone and in the simulator.
Source: (StackOverflow)
I'm trying to link a UILabel
with an IBOutlet
created in my class.
My application is crashing with the following error. What does this mean? How can I fix it?
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.'
Source: (StackOverflow)
Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay:
but with an argument like int
/double
/float
?
Source: (StackOverflow)
What setting do i need to put in my info.plist
to enable http
mode as per the error message:
Transport security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
Source: (StackOverflow)
I want to check if the iOS
version of the device is greater than 3.1.3
I tried things like:
[[UIDevice currentDevice].systemVersion floatValue]
but it does not work, I just want a:
if (version > 3.1.3) { }
How can I achieve this?
Source: (StackOverflow)
When you tap a row in a UITableView
, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?
Source: (StackOverflow)