Tuesday, July 16, 2013

Programmatically detecting isDevice iPhone 5 ?


Define global  condition as below in your global classes:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

Used C functions:
DBL_EPSILON = will give the smallest value that will make a difference when adding with one.  Smallest number such that 1.0 + DBL_EPSILON  != 1.0.
fabs = gives absolute value of x (a negative value becomes positive, positive value is unchanged).

Now simply you can detect iPhone 5 as :
if(IS_IPHONE_5){
            NSLog(@"I am iPhone 5");
}
else {
              NSLog(@"I am not iPhone 5");

}

Monday, July 15, 2013

Auto Search/Auto Complete using UITextField as SearchBar for iOS app


After a long gap, I made a time off  from my regular stuffs to write here few things. This time I choosed a topic  “Auto Search/Auto Complete” ,. You guyz already knew about this feature , if not, then auto search/Auto complete is the process of searching when you type some character in Search field. Auto search simply detects each of the character you type and starts searching. Moreover, When a user is entering data into a text field, it’s often nice to have the ability to auto complete with custom values based on what the user is entering, saving their time.

Auto Search  the name,  always sounds complicated  . Even I always thought doing auto search features in iOS app must be complicated but I was wrong . It is not hard as it sounds, and how I figured it out , I am explaining here with simply using UItextField and its native method.

Here are the step by step guidelines :

1.     First thing you need to create is UITextField which works as a search bar and UITableView for displaying your search results. And another thing is data source (Array/Dictionary) which has a collection of data from where we need to search  based on the name/strings which user types in text field.
2.     You can play with UItableView  in your own way. You simply can hide it first and when starts searching and finds result , you can unhide the table and reload the data. OR simply you can only add table view when search starts and remove it when we are done with the selection.
Here, I am using Hidden property of UItableView.
3.     Create UITextField , define <UITextFieldDelegate> in you .h file