Showing posts with label objectiveC. Show all posts
Showing posts with label objectiveC. Show all posts

Wednesday, February 26, 2014

iOS closes the active Wi-Fi connection after 30 minutes


These days I’m involved developing an app (runs on both iPad and iPhone) that relies on Wi-Fi network a lot. I happen to notice that sometimes device looses its connection to the Wi-Fi network. Rest of the team was complaining that they have to keep on going to device settings to re-connect.

Wednesday, January 1, 2014

Can’t declare variables inside a switch case – Objective C

If you were under the above impression then the answer is you can with a little bit of change to your code. I’m guessing you are used to the following format,

switch (value){
case value1:
//some code
break;
case value2:
//some code
break;
default:
//some code
break;
}

Tuesday, December 31, 2013

The truth about iOS7 being slow

I have seen many posts describing the above fact, mostly regarding running iOS7 on older devices like the iPhone 4. One truth I found in all the stuff I read is the fact about how iOS7 loads its frameworks. As you all know iOS7 is designed for 64bit. Running 32bit apps might consume more memory than otherwise. Bit hard to believe, right? But it is true. This is how it happens.

Monday, December 30, 2013

Arranging UI elements for iPad split keyboard

It is a common practice to rearrange the UI Elements when the keyboard appears (if required). If you split the keyboard (Do the split gesture or long press the keyboard hide button) the keyboard notifications UIKeyboardDidShowNotification and UIKeyboardDidHideNotification will not get called.

Tuesday, December 10, 2013

Date manipulation – Objective C

You can add/subtract days/months/years from an existing NSDate without much of complicated coding if you use NSCalendar and NSDateComponents. Following is an example how you can add a day to an existing NSDate.

Monday, September 30, 2013

UIDatePicker and iOS7

If you haven't still noticed UIDatePicker has changed in iOS7. However any app compiled using the old xcode will still have the old date picker.

Monday, September 23, 2013

NSDate - few important things

If your program logic makes decisions based on time here are few things you need to remember.

Thursday, June 13, 2013

Generate primary key - Objective C

The following code will generate a primary key using the current time stamp, a character (I have used the character 'T' in this example) and a random number. I have used this to generate primary keys for database records.

Tuesday, February 19, 2013

NSView AutoresizingMask explained

You can make your NSViews auto arrange/resize according to its superview's size by setting appropriate values using NSView's setAutoresizingMask: method. For this example's sake I'll consider elements added as subviews to the contentView of the NSWindow. NSWindow can change its size when going into full screen, when the user clicks on the resize control (green button) and when the user manually resize the window. For a better UI experience it is required to re-arrange/re-size the elements according to the change in size of the NSWindow.

Sunday, October 14, 2012

Check for both null and nil to avoid crash - objective c

Sample code

line 1: NSString *someString;
line 2: someString = [self getStringValue];
line 3: NSLog(@"length of the string = %d",[someString length]);

In the above example sometimes the code can crash at line 3. Possible reason would be that the object "someString" is either null or nil. null vs nil has always been a debate with my friends, when to use and what to check and so on. If you don't have access to the contents of "getStringValue" method you'd probably have to check for both.

if (![someString isEqual:[NSNull null]] && (someString != nil)){
NSLog(@"length of the string = %d",[someString length]);
}

Wednesday, October 3, 2012

Objective C - missing documents directory

Did you know that by using "removeItemAt:" method in NSFileManager you could actually delete the documents directory? It is bit of a scary thought and I sometimes feel that it shouldn't be the case to keep careless developers away from bugs, but unfortunately or not it is possible.

Tuesday, May 22, 2012

Can’t add UIImagePickerViewController’s view as a sub view – iOS 4

Incorrect code sample

UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate = self;
[self.navigationController.view addSubview:pickerController];
[pickerController release];

Actually there is nothing wrong with the addSubview method. The only problem is that it doesn’t load the gallery.

Friday, May 11, 2012

UINavigationBar default back button - iOS 5

It is common knowledge that the UINavigationBar will display the previous UIViewController's title in an arrow shaped button at the left hand side corner. Basically if the previous UIViewController doesn't have a title the back button won't be visible as well.

Sunday, April 1, 2012

Add files to an existing zip - objective c, ZipArchive

I'm using ZipArchive developed by aish to create zip files. ZipArchive is an Objective-C class to compress or uncompress zip files, which is based on open source code "MiniZip". It worked fine on many of the iPhone apps I developed.

Thursday, March 22, 2012

UINavigationBar tintColor, why not backgroundColor or color?

I don't know whether its just me but, whenever I'm thinking of changing the colour of an UI element first thing I would do is look for methods like setBackgroundColor or setColor before I think of subclassing the element and overriding its drawRect (for more customised application of colours you will have to override "drawRect"). Unfortunately in objective c UINavigationBar colour is reffered as tintColor. So I thought of documenting it for future reference.

Monday, March 5, 2012

Branch condition evaluates to a garbage value (Xcode Analyze tool result)

Two things you need to understand first

1. Branch condition : probably a if statement
2. Garbage value: Every variable has a garbage value prior to any initialisation

"Branch condition evaluate to a garbage value" would probably mean that there could be an instance where your code (if statement in this case) tries to evaluate a variable/object which is not initialised.

The analyze tool in Xcode gave me this as one of its analyzer results. The problem code was as follows.

Monday, January 23, 2012

UILabel/UIButton not showing text - iPhone 4

If the text is showing perfectly fine in other devices, first thing I would check is the font assigned. There is a small issue with the new Xcode version (version 4.2). Some of the fonts you get in the IB (Interface Builder) are not available in all iOS versions and devices. For example the font "Helvetica Neue Medium" is not available in iPhone 4 running iOS 4.3.5

Thursday, January 12, 2012

Getting NSStatusItem co-ordinates (Position in the NSStatusBar)

You can achieve this by setting an NSView to the NSStatusItem and getting its frame when needed.

Wednesday, November 2, 2011

Transparent NSWindow controls

If you are trying to find a way to make a NSWindow transparent then you should have a look at one of my earlier posts, titled "Draggable transparent NSWindow". Today I'm going to show you how to have the default NSWindow title bar controls (close,minimize,maximize).

Friday, October 7, 2011

UITableView section index view without sections

You must be familiar with 'sectionIndexTitlesForTableView' method which allows you to define a list of shortcuts for your sections in an UITableView (like the iPhone contacts app). What if you want a similar behaviour without having any sections? This is how you could tweak apple's default behaviour of 'sectionIndexTitlesForTableView'. Implement the following methods in the delegate class of the UITableView.