Thursday, October 3, 2013

iOS 7 (XCode 5) Tutorial - ContentSize of Text View is not calculating correctly any more with iOS 7

iOS 7 (XCode 5) ContentSize of Text View is not calculating correctly any more with iOS 7


Before X Code 5, to get the contents height of text view we use text view's property contentSize. But its no longer work with new iOS 7. 

Option 1:

With iOS 7, we have a different property named textContainer. It gives text container of text view. 

You need to replace the following line of code (These line of code set the text view frame according to its content length.)

 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = _textView.textContainer.size.height;
 _textView.frame = frame;

_textView.textContainer.size gives the same value which was given by _textView.contentSize earlier.

Option 2:

We can also replace the line of code 


 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = [_textView sizeThatFits:CGSizeMake(txtView.frame.size.width, MAXFLOAT)].height;
 _textView.frame = frame;

Above lines of code will work with each iOS.






Monday, September 30, 2013

iOS 7 ( XCode 5) Tutorial - IBAction is not working with custom cell

iOS 7 ( XCode 5) IBAction is not working with custom cell


Many of the developer used custom view to show custom cell on Table view for older version of iOS. If you are one of them, then you will have to face a problem that your button click action will no longer work with iOS7.


How to resolve this:

You have three options:

Option 1:  Create the new lay out with new table cell instead of taking view. and put all layouts again in table cell.

I know, this will require a lot of effort. If you don't want to do this, we have a very small hack for it : option 2


Option 2: Create a IBOutlet for your button and add this button as a subview of your cell's content view.


    [self.myCell.contentView addSubview:self.btn_click];


The above line of code will add btn_click as a subview of you content view. Now button click action should work.

Option 3: 

The best way : 

i) Take An outlet UITableViewCell.
ii) Make existing view as subview of new table cell.
iii) Disconnect the connection of custom cell to existing view and connect it to new UITableViewCell.

thats it, Your IBAction will work now.

May be you got the crash with error message that "class is not key value coding - compliant.". Check your old view connection and remove all connection having yellow mark.

Please don't hesitate to use comment section if you have any question.




Tuesday, January 29, 2013

Custom KeyBoard Handler With Done, Next and Previous Button



Keyword: Safari like keyboard, done, next button, tab orderring, text field, text field delegate

Custom KeyBoard Handler With Done, Next and Previous Button

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone


Get the sample code and helper file from the link

1) Copy helper files customKeyBoardHelper.h and customKeyBoardHelper.m to your project.
2) Follwing methods are provided in helper classes

  -(void)showingKeyboardHeader:(BOOL)isKeyboard;
  -(void)showingDoneButton:(BOOL)isDone;
  -(void)settingTitleForDoneButton:(NSString *)done WithImage:(UIImage *)dimg;


  -(void)addButtonWithTitle:(NSString *)tit forCustomHandler:(SEL)sel;
  -(void)addButtonWithImage:(UIImage *)img forCustomHandler:(SEL)sel;


  -(void)addButtonWithTitle:(NSString *)tit forEvent:(events)sel;
  -(void)addButtonWithImage:(UIImage *)img forEvent:(events)sel;


  -(void)addTextField:(UITextField *)txtField;
  -(void)getCustomeKeyBoard;
  -(id)initWithBaseController:(UIViewController *)ctrl;



Use of Helper Classes


1) Take a project of name KeyBoardSample.

2) Open KeyBoardSample.xib and populate 4 text fields on it. 

3) Named these as txt1,txt2,txt3 and txt4.

4) Connect all text fields outlets to .h File.

5) import customKeyBoardHelper.h to KeyBoardSample.h

5) Open .m file and modified the code of  viewDidLoad as 


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    customKeyBoardHelper *helper=[[customKeyBoardHelper alloc]initWithBaseController:self];
    [helper addTextField:self.txt1];
    [helper addTextField:self.txt3];
    [helper addTextField:self.txt2];

//  Here tab order is txt1 --> txt3 --> txt2 . You can change it.

    [helper addButtonWithTitle:@"Next" forEvent:MoveToNext];

// Two methods are provided. MoveToNext and MoveToBack
//  MoveToNext method is used to move cursor from one text field to next field.
//  MoveToBack method is used to move cursor from one text field to previous field.

   [helper addButtonWithTitle:@"Test" forCustomHandler:@selector(testtask)];

// You can also make your custom handler. Here we have made a method named testtask. We need to implement this method later.

// You can also set the image instead of giving title as 

 [helper addButtonWithImage:[UIImage imageNamed:@"imageName.png"forEvent:MoveToNext];
   
// Finally call the method to set your custom key board.   
    [helper getCustomeKeyBoard];
}


6) implement testtask method.

-(void)testtask
{



}

7) Done button is provided by default. You can hide this by using method showingDoneButton.


Get the sample code and helper files at   
http://adf.ly/IArVQ









Sunday, January 13, 2013

iPhone Post Web Service Helper

POST SERVICE HELPER 

Keywords: Post service, HTTP, Helper

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

Helper classes download at http://adf.ly/ILKC0


1)  Get the helper classes for post service from here. This helper class provides asynchronous request.

2) Methods provided by helper classes

  -(void)setURL:(NSString *)str;
  -(void)addParamValue:(NSString *)value forKey:(NSString *)key;
  -(void)addHeaderValue:(NSString *)value forKey:(NSString *)key;
  -(void)runWithController:(UIViewController *)ctrl andCallBack:(SEL)select;


Use of helper classes


i) import Post service helper class where do you want to use post service
        #import "PostServiceHelper.h"

ii) Initialise object of PostServiceHelper as 
      PostServiceHelper *helper=[[PostServiceHelper alloc]init];

iii) set URL as 

    [helper setURL:urlString];

    // url string is your url where do you want to send request.



iv) set Header as 
      [helper  addHeaderValue:value forKey:key];
      // value and key are NSString 

v) set Parameter as
     [helper addParamValue:value forKey:key];
     // value and key are NSString 

vi) Run service
    [helper runWithController:self andCallBack:@selector(callback:)];
  // callback: is a callback method


vii) You can use call back method as  

-(void)callback:(NSString *)result
{
        NSLog(@"%@", result);
// Here we are printing response , You can use this result as you want

 }

You can get the source file from here