Friday, 18 December 2015

How To Select Multiple Images From Gallary In Asset Folder Ios/Iphone

#import <CTAssetsPickerController/CTAssetsPickerController.h>


// request authorization status
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
    dispatch_async(dispatch_get_main_queue(), ^{

        // init picker
        CTAssetsPickerController *picker = [[CTAssetsPickerController

alloc] init];

        // set delegate
        picker.delegate = self;

        // Optionally present picker as a form sheet on iPad
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            picker.modalPresentationStyle = UIModalPresentationFormSheet;

        // present picker
        [self presentViewController:picker animated:YES completion:nil];
    });
}];

- (void)assetsPickerController:(CTAssetsPickerController *)picker

didFinishPickingAssets:(NSArray *)assets
{
// assets contains PHAsset objects.
}



NSArray *assets = @[asset1, asset2, asset3, ...];
CTAssetsPageViewController *vc = [[CTAssetsPageViewController alloc] 

initWithAssets:assets];
vc.pageIndex = assets.count - 1; // display the last asset

[self.navigationController pushViewController:vc animated:YES];

more Detail Visie Below Link :-

https://github.com/chiunam/CTAssetsPickerController

Wednesday, 16 December 2015

How To Set Margig Header TableVIew Ios/Iphone

UITableView has a delegate method named "viewForHeaderInSection"

. If you remove the padding an then in the delegate method
  add a padding and return the section header view.

- (UIView *)tableView:(UITableView *)

 tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]

 initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.frame), 30)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 200, 25)];

    // 15 pixel padding will come from CGRectMake(15, 5, 200, 25).
    label.text = @"2013";
    [view addSubview: label];
    return view;
}

Thursday, 10 December 2015

Work with CollectionViewCell in TableView IOs/Iphone

=> Here Used CollectionView The Using TableView In Ios
   And Used How to Perfomnce About    Using emded and ColllectionView And
   TableView Both Concept And level of The Basic Api :


- (NSInteger)tableView:(UITableView *)tableView

   numberOfRowsInSection:(NSInteger)section
{   
    return [self.articles count];
}


=> Her Used CellForRowAtIndex Path In TabeView And

    Used Delegate Method And Data sources



 - (UITableViewCell *)tableView:(UITableView *)tableView

 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"ArticleCell";

    UITableViewCell *cell = [tableView

dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil)
    {
       cell = [[[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]

autorelease];
    }

    cell.textLabel.text = @"The title of the cell in the

table within the table :O";

    return cell;
}





Monday, 7 December 2015

How To Add Multiple Line Ios/Iphone

button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// you probably want to center it
button.titleLabel.textAlignment = NSTextAlignmentCenter; // if you want to
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal]

 button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
// you probably want to center it
button.titleLabel.textAlignment = UITextAlignmentCenter;
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];

Wednesday, 2 December 2015

Work With KVO In Ios/Iphone

==> here used Kvo Key value obbserver:
- (IBAction)incNumber:(id)sender

{
    self.number++;
    NSLog(@"%d", self.number);

}
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:
  (NSKeyValueObservingOptions)options context:(void *)context;


 

Monday, 30 November 2015

How To Set Floating Pont in TableViewHeaderView Ios/Iphone

CGFloat dummyViewHeight = 40;
UIView *dummyView = [[UIView alloc]

initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width,

dummyViewHeight)];
self.tableView.tableHeaderView = dummyView;
self.tableView.contentInset = UIEdgeInsetsMake(-dummyViewHeight, 0, 0, 0);

Saturday, 28 November 2015

how to Use Url Image Reguler Expressation Ios/iphone

 
    NSString *searchedString = [[arr objectAtIndex: indexPath.row]
 objectForKey: @"description"];
   
    NSRange rangeOfString = NSMakeRange(0, [searchedString length]);
    //NSLog(@"searchedString: %@", searchedString);
   
    NSString *pattern = @"src=\"([^\"]+)\"";
    NSError* error = nil;
    NSTextCheckingResult* match;
    NSRegularExpression* regex = [NSRegularExpression
regularExpressionWithPattern:pattern options:0 error:&error];
    NSArray *matchs = [regex matchesInString:searchedString
options:0 range:rangeOfString];
    for (match in matchs) {
        NSLog(@"url: %@", [searchedString substringWithRange:
[match rangeAtIndex:1]]);
      
    }

Friday, 27 November 2015

Work Selected Row By default and Check Mark In UITableView Ios/Iphone

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.tableView selectRowAtIndexPath:indexPath
                            animated:YES
                      scrollPosition:UITableViewScrollPositionNone];
[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];





 ==> Selected Checkmark row



- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:

 CellIdentifier];

    if(cell == nil )
    {
        cell =[[[UITableViewCell alloc] initWithStyle:

 UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    if ([indexPath compare:self.lastIndexPath] == NSOrderedSame)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

// UITableView Delegate Method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:

(NSIndexPath *)indexPath
{
    self.lastIndexPath = indexPath;

    [tableView reloadData];
}

Thursday, 26 November 2015

How To Hide Navigation Bar Button ios Iphone

UIBarButtonItem *oldButton = self.navigationItem.rightBarButtonItem;
[oldButton retain];
self.navigationItem.rightBarButtonItem = nil;

//... later
self.navigationItem.rightBarButtonItem = oldButton;

Wednesday, 25 November 2015

How To Udr NSLocal Country name Ios/iphone

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];

NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]

 autorelease];

NSString *country = [usLocale displayNameForKey: NSLocaleCountryCode value:

 countryCode];

Tuesday, 24 November 2015

Work With NSNotification Center Ios/Iphone

=> Here User Dealloct Whiitch Used Notification:
- (void) dealloc
{
   
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

- (id) init
{
    self = [super init];
    if (!self) return nil;

==> add observe Notification default center:-   

    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receiveTestNotification:)
        name:@"TestNotification"
        object:nil];

    return self;
}

=> have Received Notification:-



 - (void) receiveTestNotification:(NSNotification *) notification
{
    // [notification name] should always be @"TestNotification"
    // unless you use this method for observation of other notifications
    // as well.

    if ([[notification name] isEqualToString:@"TestNotification"])
        NSLog (@"Successfully received the test notification!");
}

@end



- (void) someMethod
{

    // All instances of TestClass will be notified
    [[NSNotificationCenter defaultCenter]
        postNotificationName:@"TestNotification"
        object:self];

}
=================================================================

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:myObject

forKey:@"someKey"];
    [[NSNotificationCenter defaultCenter] postNotificationName:

 @"TestNotification" object:nil userInfo:userInfo]; 



- (void) receiveTestNotification:(NSNotification *) notification

    NSDictionary *userInfo = notification.userInfo;
    MyObject *myObject = [userInfo objectForKey:@"someKey"];
}

Saturday, 21 November 2015

How to Use Perfom Selector Ios/Iphone

dispatch_async(dispatch_get_main_queue(), ^{
    [self doSomething:1 b:2 c:3 d:4 e:5];
});



[ invocationObject performSelectorOnMainThread: @selector( invoke )

   withObject: nil, waitUntilDone: NO ];



- (void)threadMain:(id)data {
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    NSRunLoop *runloop = [NSRunLoop currentRunLoop];
    [runloop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];

    while (isAlive) { // '
        [runloop runMode:NSDefaultRunLoopMode beforeDate:

[NSDate distantFuture]];
    }

    [pool release];
}

How To Chnage Navigationbar Color Ios/iphone

==> change the back button chevron color for a specific navigation contro:
self.navigationController.navigationBar.tintColor =

 [UIColor whiteColor];
==> TO change Whole Navigation bar color:-
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];


UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"go back - now!";
backButton.tintColor =

 [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0];
self.navigationItem.backBarButtonItem = backButton;

Friday, 20 November 2015

How to pass index another UIController ios/iphone


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

 if ([[segue identifier] isEqualToString:@"showDetail"]) {
 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
 NSString *selectedNation =[[[self.tableView cellForRowAtIndexPath:

indexPath] textLabel] text];
[[segue destinationViewController] setSelectedNation:selectedNation];
 [[segue destinationViewController] setDelegate:self];
    }

Wednesday, 18 November 2015

Work With Asset Libery ios 5 in Ios/Iphone

LAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSString *photoName;
NSString *photoUrl;

 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) =

 ^(ALAsset *result, NSUInteger index, BOOL *stop)
    {
        if(result != NULL)
        {
            NSArray *arrKeys = [[result valueForProperty:

 ALAssetPropertyURLs]allKeys];            
            if([[result valueForProperty:ALAssetPropertyType]

 isEqualToString:ALAssetTypePhoto])
            {
                if([[UIDevice currentDevice] systemVersion]>=5.0))
                {
                    photoName = [[result defaultRepresentation]UTI];

                }
                else
                {
                    photoName = [[result defaultRepresentation]filename];

                }
                //Your code here
                photoUrl = [[result valueForProperty:ALAssetPropertyURLs]

 objectForKey:[arrKeys objectAtIndex:0]];

            }
        }
    };

    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) =

 ^(ALAssetsGroup *group, BOOL *stop)
    {
        if(group != nil)
        {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
    };
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:

assetGroupEnumerator failureBlock:^(NSError *error){
        NSLog(@"%@",error);
    }];

    [pool release];

Tuesday, 17 November 2015

How to populate OTP from user's sms Inbox to application directly in ios/iphone

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)

 url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (!url) {
    UIApplication * yourapplication =[UIApplication sharedApplication];
    NSString *outputpath =@"appname://data/";
    NSURL *url =[NSURL URLWithString:outputpath];
    [yourapplication openURL:url];
    return NO;
}

NSUserDefaults *defaultString =[NSUserDefaults standardUserDefaults];
NSString * commonString =[url absoluteString];
if (commonString.length<=15) {
    //
}
else
{
    [defaultString setObject:commonString forKey:@"urlString"];
}
     //send info to the screen you need and can navigate
 return YES;
}

How To Know UIButton Pressed Ios/Iphone

property (nonatomic, strong)  UIButton *btn1;
@property (nonatomic, strong) UIButton *btn2;
@property (nonatomic, strong) UIButton *btn3;

btn1.tag=1;
btn2.tag=2;
btn3.tag=3;

[btn1 addTarget:self action:@selector(difficultyButtonPressed:)

forControlEvents:UIControlEventTouchUpInside];

[btn2 addTarget:self action:@selector(difficultyButtonPressed:)

forControlEvents:UIControlEventTouchUpInside];

[btn3 addTarget:self action:@selector(difficultyButtonPressed:)

forControlEvents:UIControlEventTouchUpInside];

- (IBAction)difficultyButtonPressed:(UIButton*)sender
{
 NSLog(@"Button tag is %d",sender.tag);

     // you can use if else condition using sender.tag  like

      if(sender.tag==1)//first button related identifire
      {
           [self performSegueWithIdentifier:

          @"mainGameTurnGuess_FirstButtonIdentirier" sender:sender];
      }
      else if(sender.tag==2)//second button related identifier
      {
            [self performSegueWithIdentifier:

            @"mainGameTurnGuess_secondButtonIdentirier" sender:sender];
      }
      else   //Third button related identifier
      {
            [self performSegueWithIdentifier:

         @"mainGameTurnGuess_ThirdButtonIdentirier" sender:sender];
      }



- (IBAction)difficultyButtonPressed:(id)sender {
    UIButton *button = (UIButton *)sender;
    NSLog(@"Button tag is %d",button.tag);
}

Tuesday, 10 November 2015

How To Use UIAlertView With Login Password TextField Ios/Iphone

 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Your_Title" message:@"Your_message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

// Alert style customization
[[av textFieldAtIndex:1] setSecureTextEntry:NO];
[[av textFieldAtIndex:0] setPlaceholder:@"First_Placeholder"];
[[av textFieldAtIndex:1] setPlaceholder:@"Second_Placeholder"];
[av show];


=> Here Used Delegate file :-

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     NSLog(@"1 %@", [alertView textFieldAtIndex:0].text);
     NSLog(@"2 %@", [alertView textFieldAtIndex:1].text);
}

Wednesday, 28 October 2015

How To Use Multiple Header Section in UItableView Ios/Iphone

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake

(0, 0, tableView.frame.size.width, 18)];
    /* Create custom view to display section header... */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake

(10, 5, tableView.frame.size.width, 18)];
    [label setFont:[UIFont boldSystemFontOfSize:12]];
     NSString *string =[list objectAtIndex:section];
    /* Section header is in 0th index... */
    [label setText:string];
    [view addSubview:label];
    [view setBackgroundColor:[UIColor colorWithRed:166/255.0

green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
    return view;
}

Monday, 26 October 2015

How To Use Xml In Ios


 - (void)viewDidLoad

   {
      NSURL *url = [[NSURL alloc]initWithString:@"yourURL"];
        NSXMLParser *parser = [[NSXMLParser alloc]initWithContentsOfURL:url];
        [parser setDelegate:self];
       BOOL result = [parser parse];
   }

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)


        NSLog(@\"Did start element\");
    if ( [elementName isEqualToString:@"root"])
     {
        NSLog(@"found rootElement");
        return;
    }
    }

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)

 elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        NSLog(@"Did end element");
        if ([elementName isEqualToString:@"root"])
            {
              NSLog(@"rootelement end");
            }

    }
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
    {
        NSString *tagName = @"column";

       if([tagName isEqualToString:@"column"])
      {
           NSLog(@"Value %@",string);
      }

    }



down vote
   

This is how you can use NSXMLParser :

In your .h file declare :

NSMutableData       *webPortFolio;
NSMutableString     *soapResultsPortFolio;
NSURLConnection     *conn;

//---xml parsing---

NSXMLParser         *xmlParserPortFolio;
BOOL                elementFoundPortFolio;
NSMutableURLRequest *req;

NSString            *theXMLPortFolio;
NSString            *strSoapMsg;
UIAlertView         *alertView;











n your .m file use the following code:

-(void)callURL
{

     //Your logic to call URL.

     conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
     if (conn)
     {
         webPortFolio = [[NSMutableData data] retain];
     }
}
And to handle the response you can use following functions :

-(void)connection:(NSURLConnection *)connection

didReceiveResponse:(NSURLResponse *)response
{
    [webPortFolio setLength:0];    
}

-(void)connection:(NSURLConnection *)connection

didReceiveData:(NSData *)data
{
    [webPortFolio appendData:data];
}

-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error
{

    NSLog(@"error...................%@",[error description]);
    [webPortFolio release];
    [connection release];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{

    //Check the request and returns the response.

    NSLog(@"DONE. Received Bytes: %d", [webPortFolio length]);

    theXMLPortFolio = [[NSString alloc]
                      initWithBytes: [webPortFolio mutableBytes]
                      length:[webPortFolio length]
                      encoding:NSUTF8StringEncoding];

    //---shows the XML---

    NSLog(@"shows the XML %@",theXMLPortFolio);
    [theXMLPortFolio release];   

    if(xmlParserPortFolio)
    {
        [xmlParserPortFolio release];
    }
    xmlParserPortFolio = [[NSXMLParser alloc] initWithData: webPortFolio];
    [xmlParserPortFolio setDelegate: self];
    [xmlParserPortFolio setShouldResolveExternalEntities:YES];
    [xmlParserPortFolio parse];
    [webPortFolio release];
    [connection release];
}

//---when the start of an element is found---
-(void)  parser:(NSXMLParser *) parser
didStartElement:(NSString *) elementName
   namespaceURI:(NSString *) namespaceURI
  qualifiedName:(NSString *) qName
     attributes:(NSDictionary *) attributeDict
{

    if( [elementName isEqualToString:@"your_tag_name"])
    {
        if (!soapResultsPortFolio)
        {
            soapResultsPortFolio = [[NSMutableString alloc] init];
        }
        elementFoundPortFolio = TRUE;
        NSLog(@"Registration...%@",soapResultsPortFolio);
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {
        elementFoundPortFolio = TRUE;
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {
        elementFoundPortFolio = TRUE;
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {
        elementFoundPortFolio = TRUE;
    }

}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
    if (elementFoundPortFolio)
    {
        [soapResultsPortFolio appendString: string];
    }     
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(

 NSError *)parseError
{
    NSLog(@"Parser error %@ ",[parseError description]);
}


//---when the end of element is found---
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"your_tag_name"])
    {         
        NSLog(@"display the soap results%@",soapResultsPortFolio);
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {         
        //Perform required action
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {
        //Perform required action
    }
    else if([elementName isEqualToString:@"your_tag_name"])
    {
        //Perform required action
    }

    [soapResultsPortFolio setString:@""];
    elementFoundPortFolio = FALSE;
}

 

How To Set ScrollView Ios/Iphone

CGRect contentRect = CGRectZero;
for (UIView *view in self.scrollView.subviews) {
    contentRect = CGRectUnion(contentRect, view.frame);
}
self.scrollView.contentSize = contentRect.size;



(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.scrollView.contentSize = self.contentView.frame.size;
}

Thursday, 22 October 2015

How to Use and access SOAP web services from ios.iphone

NSURL *sRequestURL = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
    NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
    NSString *sMessageLength = [NSString stringWithFormat:@"%d", [sSOAPMessage length]];

    [myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [myRequest addValue: @"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
    [myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
    [myRequest setHTTPMethod:@"POST"];
    [myRequest setHTTPBody: [sSOAPMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];

    if( theConnection ) {
         self.webResponseData = [[NSMutableData data] retain];
    }else {
        NSLog(@"Some error occurred in Connection");

    }

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
     [self.webResponseData  setLength:0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
     [self.webResponseData  appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
     NSLog(@"Some error in your Connection. Please try again.");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
     NSLog(@"Received Bytes from server: %d", [self.webResponseData length]);
     NSString *myXMLResponse = [[NSString alloc] initWithBytes: [self.webResponseData bytes] length:[self.webResponseData length] encoding:NSUTF8StringEncoding];
     NSLog(@"%@",myXMLResponse);
}

Wednesday, 21 October 2015

How To Use MKAnotation Ios/Iphone

@implementation MapPin


@synthesize coordinate;

@synthesize title;

@synthesize subtitle;


- (id)initWithCoordinates:(CLLocationCoordinate2D)location


placeName:placeName description:description {

    self = [super init];

    if (self != nil) {

        coordinate = location;

        title = placeName;

        [title retain];

        subtitle = description;

        [subtitle retain];

    }

    return self;

}


- (void)dealloc {

    [title release];

    [subtitle release];

    [super dealloc];

}



@end

Set Dynamic UILable Size In Ios Iphone

CGSize maximumLabelSize = CGSizeMake(296,9999);

CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font
                        constrainedToSize:maximumLabelSize
                        lineBreakMode:yourLabel.lineBreakMode];

//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;

Tuesday, 20 October 2015

How to use Section in Row Using UITableView in Ios/Iphone

@interface MapPin : NSObject<MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *subtitle;

- (id)initWithCoordinates:(CLLocationCoordinate2D)location

placeName:(NSString *)placeName description:(NSString *)description;



pin = [[MapPin alloc] initWithCoordinates:[track startCoordinates]

placeName:@"Start" description:@""];
[map addAnnotation:pin];




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:

(NSIndexPath *)indexPath
{

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];

NSArray * nameArray = [self.sectionsArray objectAtIndex:indexPath.section];

PFUser *user = (PFUser*)[nameArray objectAtIndex:indexPath.row];

// PFUser *user = (PFUser*)[self.friends objectAtIndex:indexPath.section];

if (cell.accessoryType == UITableViewCellAccessoryNone)
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [self.recipients addObject:user.objectId];
NSLog(@"added:%@",user);
}
else {
    cell.accessoryType = UITableViewCellAccessoryNone;
    [self.recipients removeObject:user.objectId];
    NSLog(@"removed:%@",user);
}
// this is enough
}

Friday, 16 October 2015

How To Use Button Text Property In Ios/iphone

[myButton setTitle:@"Play" forState:UIControlStateNormal];

[myButton setTitle:@"Play" forState:UIControlStateNormal];
[myButton setTitle:@"Stop" forState:UIControlStateSelected];

Wednesday, 14 October 2015

How to Work Use of Radio Button In Ios/iphone

#import <UIKit/UIKit.h>

@interface RadioButton : UIButton

// Outlet collection of links to other buttons in the group.
@property (nonatomic, strong) IBOutletCollection(RadioButton)
 NSArray* groupButtons;

// Currently selected radio button in the group.
// If there are multiple buttons selected then it returns the first one.
@property (nonatomic, readonly) RadioButton* selectedButton;

selects second.
-(void) setSelected:(BOOL)selected;

// Find first radio with given tag and makes it selected.
// All of other buttons in the group become deselected.
-(void) setSelectedWithTag:(NSInteger)tag;

-(void) deselectAllButtons;

@end
===============================================================
#import "RadioButton.h"

@interface RadioButton()
{
    NSMutableArray* _sharedLinks;
}
@end

@implementation RadioButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        if(![[self allTargets] containsObject:self]) {
            [super addTarget:self action:@selector(onTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return self;
}

-(void) awakeFromNib
{
    if(![[self allTargets] containsObject:self]) {
        [super addTarget:self action:@selector(onTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
    }
}

-(void) addTarget:(id)target action:(SEL)action forControlEvents:
(UIControlEvents)controlEvents
{
    // 'self' should be the first target
    if(![[self allTargets] containsObject:self]) {
        [super addTarget:self action:@selector(onTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
    }
    [super addTarget:target action:action forControlEvents:controlEvents];
}

-(void) onTouchUpInside
{
    [self setSelected:YES distinct:YES sendControlEvent:YES];
}

-(void) setGroupButtons:(NSArray *)buttons
{
    if(!_sharedLinks) {
        for(RadioButton* rb in buttons) {
            if(rb->_sharedLinks) {
                _sharedLinks = rb->_sharedLinks;
                break;
            }
        }
        if(!_sharedLinks) {
            _sharedLinks = [[NSMutableArray alloc] initWithCapacity:[buttons count]+1];
        }
    }

    BOOL (^btnExistsInList)(NSArray*, RadioButton*) = ^(NSArray* list, RadioButton* rb){
        for(NSValue* v in list) {
            if([v nonretainedObjectValue]==rb) {
                return YES;
            }
        }
        return NO;
    };

    if(!btnExistsInList(_sharedLinks, self)) {
        [_sharedLinks addObject:[NSValue valueWithNonretainedObject:self]];
    }

    for(RadioButton* rb in buttons) {
        if(rb->_sharedLinks!=_sharedLinks) {
            if(!rb->_sharedLinks) {
                rb->_sharedLinks = _sharedLinks;
            } else {
                for(NSValue* v in rb->_sharedLinks) {
                    RadioButton* vrb = [v nonretainedObjectValue];
                    if(!btnExistsInList(_sharedLinks, vrb)) {
                        [_sharedLinks addObject:v];
                        vrb->_sharedLinks = _sharedLinks;
                    }
                }
            }
        }
        if(!btnExistsInList(_sharedLinks, rb)) {
            [_sharedLinks addObject:[NSValue valueWithNonretainedObject:rb]];
        }
    }
}

-(NSArray*) groupButtons
{
    if([_sharedLinks count]) {
        NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:
[_sharedLinks count]];
        for(NSValue* v in _sharedLinks) {
            [buttons addObject:[v nonretainedObjectValue]];
        }
        return buttons;
    }
    return nil;
}

-(RadioButton*) selectedButton
{
    if([self isSelected]) {
        return self;
    } else {
        for(NSValue* v in _sharedLinks) {
            RadioButton* rb = [v nonretainedObjectValue];
            if([rb isSelected]) {
                return rb;
            }
        }
    }
    return nil;
}

-(void) setSelected:(BOOL)selected
{
    [self setSelected:selected distinct:YES sendControlEvent:NO];
}

-(void) setButtonSelected:(BOOL)selected sendControlEvent:(BOOL)sendControlEvent
{
    BOOL valueChanged = (self.selected != selected);
    [super setSelected:selected];
    if(valueChanged && sendControlEvent) {
        [self sendActionsForControlEvents:UIControlEventValueChanged];
    }
}

-(void) setSelected:(BOOL)selected distinct:(BOOL)distinct sendControlEvent:(BOOL)sendControlEvent
{
    [self setButtonSelected:selected sendControlEvent:sendControlEvent];

    if( distinct && (selected || [_sharedLinks count]==2) )
    {
        selected = !selected;
        for(NSValue* v in _sharedLinks) {
            RadioButton* rb = [v nonretainedObjectValue];
            if(rb!=self) {
                [rb setButtonSelected:selected sendControlEvent:sendControlEvent];
            }
        }
    }
}

-(void) deselectAllButtons
{
    for(NSValue* v in _sharedLinks) {
        RadioButton* rb = [v nonretainedObjectValue];
        [rb setButtonSelected:NO sendControlEvent:NO];
    }
}

-(void) setSelectedWithTag:(NSInteger)tag
{
    if(self.tag == tag) {
        [self setSelected:YES distinct:YES sendControlEvent:NO];
    } else {
        for(NSValue* v in _sharedLinks) {
            RadioButton* rb = [v nonretainedObjectValue];
            if(rb.tag == tag) {
                [rb setSelected:YES distinct:YES sendControlEvent:NO];
                break;
            }
        }
    }
}

- (void)dealloc
{
    for(NSValue* v in _sharedLinks) {
        if([v nonretainedObjectValue]==self) {
            [_sharedLinks removeObjectIdenticalTo:v];
            break;
        }
    }
}


@end







Tuesday, 13 October 2015

How to Add Plus Button In TableView Cell Ios/iphone

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button setUserInteractionEnabled:NO];
cell.accessoryView = button;

Monday, 12 October 2015

How To Work With CoreData Ios/Iphone

=> here work Core Data:-

#import <UIKit/UIKit.h>

@interface DeviceDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *versionTextField;
@property (weak, nonatomic) IBOutlet UITextField *companyTextField;
@property (strong) NSManagedObject *device;
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;

@end

#import "DeviceDetailViewController.h"

@interface DeviceDetailViewController ()

@end

@implementation DeviceDetailViewController
@synthesize device;

- (NSManagedObjectContext *)managedObjectContext {
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }
    return context;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.device) {
        [self.nameTextField setText:[self.device valueForKey:@"name"]];
        [self.versionTextField setText:[self.device valueForKey:@"version"]];
        [self.companyTextField setText:[self.device valueForKey:@"company"]];
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)save:(id)sender {
    NSManagedObjectContext *context = [self managedObjectContext];
   
    if (self.device) {
        // Update existing device
        [self.device setValue:self.nameTextField.text forKey:@"name"];
        [self.device setValue:self.versionTextField.text forKey:@"version"];
        [self.device setValue:self.companyTextField.text forKey:@"company"];

    } else {
        // Create a new device
        NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Device" inManagedObjectContext:context];
        [newDevice setValue:self.nameTextField.text forKey:@"name"];
        [newDevice setValue:self.versionTextField.text forKey:@"version"];
        [newDevice setValue:self.companyTextField.text forKey:@"company"];
    }
   
    NSError *error = nil;
    // Save the object to persistent store
    if (![context save:&error]) {
        NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
    }
   
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end

#import "DeviceViewController.h"
#import "DeviceDetailViewController.h"

@interface DeviceViewController ()
@property (strong) NSMutableArray *devices;
@end

@implementation DeviceViewController

- (NSManagedObjectContext *)managedObjectContext {
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }
    return context;
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
   
    // Fetch the devices from persistent data store
    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Device"];
    self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
   
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.devices.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
   
    // Configure the cell...
    NSManagedObject *device = [self.devices objectAtIndex:indexPath.row];
    [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [device valueForKey:@"name"], [device valueForKey:@"version"]]];
    [cell.detailTextLabel setText:[device valueForKey:@"company"]];
   
    return cell;
}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObjectContext *context = [self managedObjectContext];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete object from database
        [context deleteObject:[self.devices objectAtIndex:indexPath.row]];
       
        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
            return;
        }
       
        // Remove device from table view
        [self.devices removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }  
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }  
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}


#pragma mark - Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"UpdateDevice"]) {
        NSManagedObject *selectedDevice = [self.devices objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
        DeviceDetailViewController *destViewController = segue.destinationViewController;
        destViewController.device = selectedDevice;
    }
}

@end


Sunday, 11 October 2015

Work With Local Notification In Ios/iphone

=> Here Used One Class ViewController:-

=> NotifierViewController.h file looks like.
=> Also taken Method Action:-

@interface NotifierViewController : UIViewController&lt;UITableViewDelegate,UITableViewDataSource&gt; {
    IBOutlet UITableView *tableview;
    IBOutlet UIDatePicker *datePicker;
    IBOutlet UITextField *eventText;
}

@property (nonatomic, retain) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) IBOutlet UITextField *eventText;

- (IBAction) scheduleAlarm:(id) sender;

@end
==> Here used Implemention file :-

@implementation NotifierViewController

@synthesize datePicker,tableview, eventText;

- (IBAction) scheduleAlarm:(id) sender {

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    datePicker = nil;
    tableview = nil;
    eventText = nil;
}

- (void)dealloc {
    [super dealloc];
}

@end
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // We only have one section
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of notifications
    return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // Get list of local notifications
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];

    // Display notification info
    [cell.textLabel setText:notif.alertBody];
    [cell.detailTextLabel setText:[notif.fireDate description]];

    return cell;
}
=> Here Work With Sheduler Alerm :-

- (IBAction) scheduleAlarm:(id) sender {
    [eventText resignFirstResponder];

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

    // Get the current date
    NSDate *pickerDate = [self.datePicker date];

    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
                                                   fromDate:pickerDate];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
                                                   fromDate:pickerDate];
    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
    // Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
    [dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    // Notification details
    localNotif.alertBody = [eventText text];
    // Set the action button
    localNotif.alertAction = @"View";

    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;

    // Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    localNotif.userInfo = infoDict;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

    [self.tableview reloadData];
}

=> App delegate .m file and Add the following code:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    application.applicationIconBadgeNumber = 0;

    // Handle launching from a notification
    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSLog(@"Recieved Notification %@",localNotif);
    }

    return YES;
}

 - (void)application:(UIApplication *)app didReceiveLocalNotification:
   (UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);
}

Friday, 9 October 2015

Login Username And Password With Facebook for iOS/Iphone

==>  Working With login in ios 5 and ios 6 , Using  FBLoginView Class ,
    simplest way to login into facebook using Facebook sdk .

    FBLoginView * pFBLoginViewObj = [[FBLoginView alloc] init];
    [pFBLoginViewObj setFrame:self.view.frame];
    pFBLoginViewObj.delegate = self;//optional
    [self.view addSubview:pFBLoginViewObj];

How to Pass Data One ViewController to Another View Ios/Iphone

=> Here Taken One Example ViewControllerA and ViewControllerB

=>For Here Used pass a BOOL value from ViewControllerA to ViewControllerB:-.

    In ViewControllerB.h declared one property for the BOOL variable:

    @property(nonatomic) BOOL *isSomethingEnabled;

    In ViewControllerA you need to Say ViewControllerB so use It:-

    #import "ViewControllerB.h"

=>  Then where you want to load the view eg. didSelectRowAtIndex or some IBAction
    you need to set the property in ViewControllerB before you push it onto nav stack.

    ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
    viewControllerB.isSomethingEnabled = YES;
    [self pushViewController:viewControllerB animated:YES];

    This will set isSomethingEnabled in ViewControllerB to BOOL value YES.

==> Here Passing Data Forward Using The Segue's:-

==> If you are using Storyboards you are most likely using segues and
    will need this procedure to pass data forward. This is similar to the above but instead of passing
    the data before you push the view controller, you use a method called:-

=> Here Used One Of the Method Whitch is:-

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

==> Here Pass a BOOL from ViewControllerA to ViewControllerB:-

    In ViewControllerB.h create a property for the BOOL

    @property(nonatomic) BOOL *isSomethingEnabled;

    in ViewControllerA you need to tell it about ViewControllerB so use an

    #import "ViewControllerB.h"

=> Create a the segue from ViewControllerA to ViewControllerB on the storyboard and give it an identifier,
   in this example we'll call it "showDetailSegue"

=> Next we need to add the method to ViewControllerA that is called when any segue is performed,
   because of this we need to detect which segue was called and then do something.
   In our example we will check for "showDetailSegue"
   and if thats performed we will pass our BOOL value to ViewControllerB:-

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
        if([segue.identifier isEqualToString:@"showDetailSegue"]){
            ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
            controller.isSomethingEnabled = YES;
        }
    }

=>If you have your views embedded in a navigation controller you need to change the
   method above slightly to the following

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
        if([segue.identifier isEqualToString:@"showDetailSegue"]){
            UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
            ViewControllerB *controller = (ViewControllerB *)navController.topViewController;
            controller.isSomethingEnabled = YES;
        }
    }

=> This will set isSomethingEnabled in ViewControllerB to BOOL value YES.

==> Passing Data Back


    In ViewControllerB.h, below the #import, but above @interface you specify the protocol.

    @class ViewControllerB;

    @protocol ViewControllerBDelegate <NSObject>
 - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
    @end

=> Next still in the ViewControllerB.h you need to setup a delegate property and
   synthesize in ViewControllerB.m

    @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;

=> In ViewControllerB we call a message on the delegate when we pop the view controller.

    NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
    [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];

=> That's it for ViewControllerB. Now in ViewControllerA.h, tell ViewControllerA to
   import ViewControllerB and conform to its protocol.

    #import "ViewControllerB.h"

    @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
=>    In ViewControllerA.m implement the following method from our protocol

    - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
    {
        NSLog(@"This was returned from ViewControllerB %@",item);
    }

=>  We need to tell ViewControllerB that ViewControllerA is its delegate before
    we push ViewControllerB on to nav stack:-

    ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
    viewControllerB.delegate = self
    [[self navigationController] pushViewController:viewControllerB animated:YES];

How to use Protocol In Ios/iphone

==> Here One Protocol Declared :
@protocol MyProtocol <NSObject>

=> Declared One Of the Method :-

  - (void)aRequiredMethod;

=> Here Required Method:
 @required
- (void)anotherRequiredMethod;

@optional
- (void)anOptionalMethod;

@end

@interface MyClass <MyProtocol>

@end

@property (nonatomic, weak) id<MyProtocol> delegate;

[self.delegate aRequiredMethod];

[self.delegate conformsToProtocol:@protocol(MyProtocol)]

[self.delegate respondsToSelector:@selector(anOptionalMethod)]

Thursday, 8 October 2015

Use Category With Custom Method In Ios/Iphone

=> Here Seeing One Of the Imporetd Categortt Concept:=

#import <objc/runtime.h>

static void *MyClassResultKey;
@implementation MyClass

=> Here taken One method Of which Using Category In Ios:

 - (NSString *)test {

  NSString *result = objc_getAssociatedObject(self, &MyClassResultKey);
  if (result == nil)

{
    // do a lot of stuff
    result = ...;
    objc_setAssociatedObject(self, &MyClassResultKey,

                  result, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  }
  return result;
}
=> finaly Object set Associate object Using Category:-

 @end

Wednesday, 7 October 2015

How to Use Completion Block In Ios/iphone

=> Here Work with returnType (.h above @interface declaration)

=> typedef void (^CompleteDiceRolling)(NSInteger diceValue);

    Declared With One Of the a @property for the block (.h)

    @property (copy, nonatomic) CompleteDiceRolling completeDiceRolling;

    Declared here One Of a Method with finishBlock (.h)

    - (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))

     finishBlock;

=>  Use Periviose Method in .m file and commit finishBlock to @property
    declared before:-

    - (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))

     finishBlock{
        self.completeDiceRolling = finishBlock;
    }

=>  Here Use completionBlock Pass Predefined variableType to it
    (Don't forget to check whether the completionBlock exists):-

    if( self.completeDiceRolling ){
        self.completeDiceRolling(self.dieValue);
    }

    => Finaly Use it With Work Completion Block.

Tuesday, 6 October 2015

How to Set Row As per Cell Of UITableView Ios /Iphone

==> Here Used One of the UITbaleVIew Delegate and DataSourse file method:-

- (NSInteger)tableView:(UITableView *)tableView

 numberOfRowsInSection:(NSInteger)section {
return [[tmpArray objectAtIndex:section] count];
}

Monday, 5 October 2015

Work With Payu Money In Ios/Iphone

=> Here Used One the Example Of the Payu Money Concept:-

    int i = arc4random() % 9999999999;
    NSString *strHash = [self createSHA512:[NSString

    stringWithFormat:@"%d%@",i,[NSDate date]]];

 // Generatehash512(rnd.ToString() + DateTime.Now);
    NSString *txnid1 = [strHash substringToIndex:20];
    NSLog(@"tnx1 id %@",txnid1);
    NSString *key = @"JBZaLc";
    NSString *amount = @"1000";
    NSString *productInfo = @"Nice product";
    NSString *firstname = @"Mani";
    NSString *email = @"mani.ingenius@gmail.com";
    NSString *phone = @"1234566";
    NSString *surl = @"www.google.com";
    NSString *furl = @"www.google.com";
    NSString *serviceprovider = @"payu_paisa";
    NSString *hashValue = [NSString stringWithFormat:

    @"%@|%@|%@|%@|%@|%@|||||||||||GQs7yium",key,txnid1,amount,

    productInfo,firstname,email];
    NSString *hash = [self createSHA512:hashValue];
    NSDictionary *parameters = [NSDictionary

    dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,
    amount,productInfo,firstname,email,phone,surl,furl,hash,serviceprovider
    ,nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",

    @"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash",

    @"service_provider", nil]];
    __block NSString *post = @"";
    [parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if ([post isEqualToString:@""]) {
            post = [NSString stringWithFormat:@"%@=%@",key,obj];
        }else{
            post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
        }

    }];
   NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
   allowLossyConversion:YES];
   NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)
   [postData length]];
   NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
   [request setURL:[NSURL URLWithString:[NSString stringWithFormat:

   @"https://test.payu.in/_payment"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded"

   forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    [_webviewSample loadRequest:request];

==> Here Used One Method Which is Encrypted SHA512 Password:-

-(NSString *)createSHA512:(NSString *)string
{
    const char *cstr = [string cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data = [NSData dataWithBytes:cstr length:string.length];
    uint8_t digest[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512(data.bytes, (CC_LONG)data.length, digest);
    NSMutableString* output = [NSMutableString

    stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];
    return output;
}

How To Work Lazy Loding With UITableView In Ios/Iphone

=> Here Used ForPayu Money Concept:-
=> How to Use It:-
#import "ViewController.h"

#import "UIImageView+WebCache.h"
@interface ViewController ()
{
NSArray *arrImagesUrl;
}
@end
@implementation ViewController


- (void)viewDidLoad{


[super viewDidLoad];
arrImagesUrl = [[NSArray alloc] initWithObjects:
@"http://static2.dmcdn.net/static/video/974/848/51848479:jpeg_preview_small.jpg?20121105222657",
@"http://static2.dmcdn.net/static/video/274/848/51848472:jpeg_preview_small.jpg?20121105222644",
@"http://static2.dmcdn.net/static/video/954/848/51848459:jpeg_preview_small.jpg?20121105222637",
@"http://static2.dmcdn.net/static/video/554/848/51848455:jpeg_preview_small.jpg?20121105222615",
@"http://static2.dmcdn.net/static/video/944/848/51848449:jpeg_preview_small.jpg?20121105222558",
@"http://static2.dmcdn.net/static/video/144/848/51848441:jpeg_preview_small.jpg?20121105222556",
@"http://static2.dmcdn.net/static/video/134/848/51848431:jpeg_preview_small.jpg?20121105222539",
@"http://static2.dmcdn.net/static/video/624/848/51848426:jpeg_preview_small.jpg?20121105222523",
@"http://static2.dmcdn.net/static/video/281/448/51844182:jpeg_preview_small.jpg?20121105222502",
@"http://static2.dmcdn.net/static/video/414/848/51848414:jpeg_preview_small.jpg?20121105222516",
@"http://static2.dmcdn.net/static/video/171/848/51848171:jpeg_preview_small.jpg?20121105223449",
@"http://static2.dmcdn.net/static/video/904/848/51848409:jpeg_preview_small.jpg?20121105222514",
@"http://static2.dmcdn.net/static/video/004/848/51848400:jpeg_preview_small.jpg?20121105222443",
@"http://static2.dmcdn.net/static/video/693/848/51848396:jpeg_preview_small.jpg?20121105222439",
@"http://static2.dmcdn.net/static/video/401/848/51848104:jpeg_preview_small.jpg?20121105222832",
@"http://static2.dmcdn.net/static/video/957/648/51846759:jpeg_preview_small.jpg?20121105223109",
@"http://static2.dmcdn.net/static/video/603/848/51848306:jpeg_preview_small.jpg?20121105222324",
@"http://static2.dmcdn.net/static/video/990/848/51848099:jpeg_preview_small.jpg?20121105222807", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - TableView Delegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
  (NSInteger)section
{
return arrImagesUrl.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
  (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"Image #%d", indexPath.row];
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
[cell.imageView setImageWithURL:[NSURL URLWithString:[arrImagesUrl objectAtIndex:indexPath.row]]

=> placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
 return cell;
}
@end
- (void)viewDidLoad
{
[superviewDidLoad];
arrImagesUrl = [[NSArrayalloc] initWithObjects:
@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705",
@"http://static2.dmcdn.net/static/video/629/228/44822926:jpeg_preview_small.jpg?20120509181018",
@"http://static2.dmcdn.net/static/video/116/367/44763611:jpeg_preview_small.jpg?20120509101749",
@"http://static2.dmcdn.net/static/video/340/086/44680043:jpeg_preview_small.jpg?20120509180118",
@"http://static2.dmcdn.net/static/video/666/645/43546666:jpeg_preview_small.jpg?20120412153140",

nil];
}

Sunday, 4 October 2015

How To Create Databse .DB Sqlite File In Ios/iphone

=> Hare Call the Method Of Whitch Declared Belove Side:

-(BOOL)application:(UIApplication *)application

 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    [self createDb];

    return YES;
}
==> Create One Databse File And Create Db And Usingf Some Method:

 -(void)createDb
{
    NSArray *dir=NSSearchPathForDirectoriesInDomains

   (NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *dbPath=[NSString

    stringWithFormat:@"%@/userDb.sqlite",[dir lastObject]];

    sqlite3 *db;

    NSFileManager *fm=[NSFileManager new];

    if([fm fileExistsAtPath:dbPath isDirectory:nil])
    {
        NSLog(@"Database already exists..");
        return;
    }

    if (sqlite3_open([dbPath UTF8String],&db)==SQLITE_OK)
    {
        const char *query="create table user

    (userName VARCHAR(20),userAdd VARCHAR(20), userPass VARCHAR(20))";

        if (sqlite3_exec(db, query, NULL, NULL, NULL)==SQLITE_OK)
        {
            NSLog(@"User table created successfully..");
        }else
        {
            NSLog(@"User table creation failed..");
        }

    }else
    {
        NSLog(@"Open table failed..");
    }
    sqlite3_close(db);
}

Saturday, 3 October 2015

How To Use Animated ANd Hide Show UIView In Ios/Iphone

==> First Take Pne IBOutlet Of UIView And Then Use Animated:
==> How to Hide ANd Show Some Kind Of UIView In Ios:
import <UIKit/UIKit.h>

@interface ViewController: UIViewController
@property (strong, nonatomic) IBOutlet UIView *cautionView;


- (IBAction)btnToggleClick:(id)sender;
@property (strong, nonatomic) IBOutlet UIButton *btnToggle;
@end
.m file:

#import "ViewController.h"

@interface ViewController()
@end

@implementation ViewController

bool isShown = false;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
=> USe tHIS Action To toggle Click On Button:-
 - (IBAction)btnToggleClick:(id)sender {
    if (!isShown) {
        _cautionView.frame =  CGRectMake(130, 20, 0, 0);
        [UIView animateWithDuration:0.25 animations:^{
            _cautionView.frame =  CGRectMake(130, 30, 100, 200);
        }];
        isShown = true;
    } else {
        [UIView animateWithDuration:0.25 animations:^{
            _cautionView.frame =  CGRectMake(130, 30, 0, 0);
        }];
        isShown = false;
    }
}
=> Based ON Button Click Hide And Show And Make UIView Frmae Size On
   Button Clikced:-

Friday, 2 October 2015

Use of Username And Pasword Post Method In Ios/Iphone

==> Here,  How can use of POST Method.: And Pass Parameter Username Password:

1. Use Some Like String With Actual Username And Password.

   NSString *post = [NSString stringWithFormat:@"Username=%@&Password=%@",
   @"username",@"password"];

2. PostString  That Encoding using NSASCIIStringEncoding  also

=> You Need Send That Post String To  NSData Format.


    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
    allowLossyConversion:YES];


=> You need to send the actual length of your data. Calculate the length of
   the post string.

    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

3. Use Object  a UrlRequest with  Properties Like HTTP Method,

=>  HTTP Header Field With Length of
    Post String. Create URLRequest object and initialize it.

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

 =>   Set That URL Whitch going to Send The Data To That Request.

     [request setURL:[NSURL URLWithString:

     @"http://www.abcde.com/xyz/login.aspx"]];

 =>  Now, set HTTP method (POST or GET). Write this lines as it is in your code.

     [request setHTTPMethod:@"POST"];

 =>  Set HTTP header field with length of the post data.

    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

 => Set Also Here Encoded Value For HTTP Header:-

   [request setValue:@"application/x-www-form-urlencoded"
   forHTTPHeaderField:@"Content-Type"];


=> Set UrlRequest with PostData To HttpBody:-

    [request setHTTPBody:postData];

 4. Create URLConnection object. Initialize it Using With The URLRequest.

   NSURLConnection *conn = [[NSURLConnection alloc]
   initWithRequest:request  delegate:self];

=> It returns the initialized URL connection , load the data for the URL request.
   You can check URL connection Based On Below Code  if/else statement as below.


    if(conn) {
    NSLog(@"Connection Successful");
    }  else {
    NSLog(@"Connection could not be made");
}
5.  To receive the data from the HTTP request , you can use the delegate

    methods provided by the URLConnection Class Reference.

    Delegate methods are as below.

=>// This method is used to receive the data which

   we get using post method.

- (void)connection:(NSURLConnection *)connection

didReceiveData:(NSData*)data

// This method receives the error report in case of connection is

not made to server.


- (void)connection:(NSURLConnection *)connection

didFailWithError:(NSError *)error

// This method is used to process the data after connection

has made successfully.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection

Post method to send request And Response In Ios /Iphone

 ==> Here Usd some IBOUTLET Of NSUrlCOnnection and
==> Used Some NsmutableData Object Using it Work it.

@property (retain, nonatomic) NSURLConnection *connection;
@property (retain, nonatomic) NSMutableData *receivedData;


==> Use this method to post some

-(void)postMethod
{
    [self.connection cancel];

    //initialize new mutable data

    NSMutableData *data = [[NSMutableData alloc] init];

    self.receivedData = data;

    //initialize url that is going to be fetched.

    NSURL *url = [NSURL URLWithString:@"http://192.168.0.176/idictionary/index.php?r=login"];

    //initialize a request from url

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL]];

    //set http method

    [request setHTTPMethod:@"POST"];

==> Here  data whitch Using Post Data

    NSString *postData = @"mac_id=val2&email_id=abc@gmail.com&password=abcfggkjhkj";


==>Here You Heve to Give To Some Parameter Vakue That You Want:

    //set request content type we MUST set this value.

    [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

    //set post data of request

    [request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];

    //initialize a connection from request

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    self.connection = connection;
    //start the connection

    [connection start];

}
==> Add Some Deleget file Of Method And Action Which Help it.

/*

=> this method might be calling more than one times according to incoming data size
 */

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

    [self.receivedData appendData:data];
}
/*

 if there is an error occured, this method will be called by connection
 */

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"%@" , error);
}
/*

==>  if data is successfully received, this method will be called by connection

 */
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{

    //initialize convert the received data to string with UTF8 encoding

    NSString *htmlSTR = [[NSString alloc] initWithData:self.receivedData

                                              encoding:NSUTF8StringEncoding];

   // NSLog(@"%@" , htmlSTR);
    NSError *e = nil;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: self.receivedData options:
    NSJSONReadingMutableContainers error: &e]; <== Here used One Parser Called   SBJson Prser

    NSLog(@"data %@",jsonArray);  <== here Some OutPut Display

    //show controller with navigation
}

Push viewController from code and storyboard In Ios

PlaceViewController *newView = 
 [self.storyboard instantiateViewControllerWithIdentifier:
@"storyBoardIdentifier"];
[self.navigationController pushViewController:newView animated:YES];
 
 
 
 

For Storyboards, you should use performSegueWithIdentifier like so: 
[self performSegueWithIdentifier:@"identifier goes here" sender:self];