Pages

Saturday, April 2, 2011

iphone: Remember always small thing

  1. Enable Keyboard return button for Textfield
  2. Enable Keyboard return button for SearchBar
  3. Deselect the UITableCell
  4. open safari from Application
  5. Convert NSData to NSString.
  6. Convert NSString to NSData
  7. Change UIAlertView Button Color
  8. To scroll the view at time of Editing textfield and keyboard appear.
  9. Get the Index path of table Row by UITextfield (UItextField in Table View).





Enable Keyboard return button for Textfield:
this button call following fuction default:
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
  [textField resignFirstResponder]; 
   return YES; 

}
Enable Keyboard return button for SearchBar:
this button call following fuction default:

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
searchBar.showsCancelButton = NO;
}


Deselect the UITableCell:
By Default, when we select the table cell it Become Blue so we can avoid it by

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)  newIndexPath 
{ 
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]; 
}

open safari from Application:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"Enter URL Here"]];

Convert NSData to NSString:

NSString *str = [[NSString alloc] initWithData:aData encoding:NSASCIIStringEncoding];

Convert NSString to NSData:
NSData *data = [aStr dataUsingEncoding: NSASCIIStringEncoding];


Change UIAlertView Button Color:

Create the object of UIAlertView , the call automatically following method:
- (void)willPresentAlertView:(UIAlertView *)alertView 
[[[alertView subviews] objectAtIndex:1] setBackgroundColor:[UIColor redColor]];
    /*
      Here index 0 = Title , 1 = cancel Button , 2,3.... = otherButton
*/

To scroll the view at time of Editing textfield and keyboard appear: 
just set the frame of view in textFieldDidBeginEditing such as:
     self.view.frame=CGRectMake(0,-30, 320, 460);
and again set the view in textFieldDidEndEditing as:
    self.view.frame=CGRectMake(0,0, 320, 460);




Get the Index path of table Row by table field such as in  textFieldDidBeginEditing method:

    When we use text field in UITableView.

- (void) textFieldDidBeginEditing:(UITextField *)textField 
{
UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
NSIndexPath *path = [mytable indexPathForCell:cell]; 

    // use this path as indexpath of table fuction

}

No comments:

Post a Comment