Thursday, 29 December 2011

Hiding BackButton in Navigation bar

self.navigationItem.hidesBackButton=YES;

Hiding Navigation Bar By Set Alpha.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
      [self.navigationController.navigationBar setAlpha:0.0];
  // [self.navigationController.navigationBar setAlpha:1.0];
   
}

 - (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setAlpha:1.0];
  
}

Wednesday, 28 December 2011

Pushing a viewController in Story Board.



UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"anotherViewController22"];
    //[vc setModalPresentationStyle:UIModalPresentationFullScreen];  
    
    [self.navigationController pushViewController:vc animated:YES];

Adding Data to a server from the app-iPhone

//Adding username and password to a mysql table hosted in a server with two fields user and pass.


-(IBAction)AddData:(id)sender{
    NSURL *url = [NSURL URLWithString:@"http://sweans.org/test-saf/rss/"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    
    NSString* appendStr = [NSString stringWithFormat:@"user=%@&pass=%@",textUser.text,textPass.text];
    
    NSData *requestData = [appendStr dataUsingEncoding:NSUTF8StringEncoding];
    
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
    [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [theRequest setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPBody: requestData];
    
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if( theConnection )
    {
        responseData = [NSMutableData data];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }

    
    
}



-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [responseData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [responseData appendData:data];
    
   // NSLog(@"Data from server%@",responseData);
    
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
   // [connection release];
  //  [responseData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [responseData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: [responseData mutableBytes] length:[responseData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",theXML);
   // [theXML release];
}

Making a connection with the Server from the app(Methods)



In Story board(Automatic reference counting)

-(IBAction)FetchData:(id)sender{
    
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://sweans.org/test-saf/rss/"]cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if (theConnection) {
        //responseData = [[NSMutableData data] retain];

        responseData = [NSMutableData data];
    } else {
        
        // Inform the user that the connection failed.
        NSLog(@"theConnection is NULL");
    }
}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [responseData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [responseData appendData:data];
    
   // NSLog(@"Data from server%@",responseData);
    
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
   // [connection release];
  //  [responseData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [responseData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: [responseData mutableBytes] length:[responseData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",theXML);
   // [theXML release];
}

Thursday, 22 December 2011

Search bar code in UiTable View.

//in .h

@interface SecondViewController : UIViewController<UISearchBarDelegate>{
   
    NSMutableArray *nameStored;
    IBOutlet UITableView *table;
    NSMutableArray *searchResult;
    NSArray *sections;
    BOOL isSearchOn;
    BOOL canSelectRow;   
   
    //IBOutlet UITableView *theTableView;
    IBOutlet UISearchBar *searchBar;
   
}

- (void) doneSearching: (id)sender;
- (void) searchSoundsTableView;

//.m

- (void)viewDidLoad {
nameStored = [[NSMutableArray alloc] initWithObjects:
                 @"Aaron",
                 @"Abaddon",
                 @"Abana",
                 @"Abba",
                 @"Abdias",nil];

searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
   
    searchResult = [[NSMutableArray alloc] init];
   
    isSearchOn = NO;
    canSelectRow = YES;
   
    sections = [NSArray arrayWithObjects: @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil];

}

- (void) doneSearching:(id)sender {
    isSearchOn = NO;
    canSelectRow = YES;
    //self.ta.scrollEnabled = YES;
    //self.navigationItem.rightBarButtonItem = nil;
   
    //---hides the keyboard---
    [searchBar resignFirstResponder];
    //---refresh the TableView---
    //[self.theTableView reloadData];
    [table reloadData];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [searchBar resignFirstResponder];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar1 {
    // Clear the search text
    // Deactivate the UISearchBar
    searchBar1.text=@"";
    [searchBar1 resignFirstResponder];
    isSearchOn = NO;
    canSelectRow = YES;
    table.scrollEnabled = YES;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1 {
    [searchBar1 resignFirstResponder];
    [self searchSoundsTableView];
}

- (void) searchSoundsTableView {
    //---clears the search result---
    [searchResult removeAllObjects];
   
    for (NSString *str in nameStored)
    {
        //NSRange titleResultsRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch];
       
        NSRange titleResultsRange = [str rangeOfString:searchBar.text options:(NSAnchoredSearch | NSCaseInsensitiveSearch)];
        if (titleResultsRange.length > 0)
            [searchResult addObject:str];
       
    }
}


- (NSIndexPath *)tableView :(UITableView *)theTableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (canSelectRow)
        return indexPath;
    else
        return nil;
}

- (void)searchBar:(UISearchBar *)searchBar1 textDidChange:(NSString *)searchText {
    [searchResult removeAllObjects];
    //---if there is something to search for---
    if ([searchText length] > 0) {
        isSearchOn = YES;
        canSelectRow = YES;
        table.scrollEnabled = YES;
        [self searchSoundsTableView];
       
    }
    else {
        //---nothing to search---
        isSearchOn = NO;
        canSelectRow = NO;
        table.scrollEnabled = YES;
    }   
    [table reloadData];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (isSearchOn) {
        return 1;
    }
   
    else
        return [nameStored count];
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    if (isSearchOn) {
        NSArray*temp=[NSArray arrayWithObject:[[searchBar.text substringToIndex:1] uppercaseString]];
        return temp;
    }
    else
        return sections;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index {
    if (isSearchOn) {
        //NSUInteger indexOfTheObject = [self.sections indexOfObject:searchBar.text];
        // return indexOfTheObject;
        return 1;
    }
    else
        return index;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
   
    if (isSearchOn) {
       
        return [[searchBar.text substringToIndex:1]uppercaseString];
    }
   
    else
    {
       
        return [sections objectAtIndex:section];
    }
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
   
   
    if (isSearchOn) {
        NSArray *sectionArray = [searchResult filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [[searchBar.text substringToIndex:1]uppercaseString]]];
        return [sectionArray count];
    } else
    {
        NSArray *sectionArray = [nameStored filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [sections objectAtIndex:section]]];
        return [sectionArray count];
       
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 35.0;  
}
- (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];
    }
   
    // Configure the cell.
    if (isSearchOn) {       
        NSString *cellValue = [searchResult objectAtIndex:indexPath.row];
        cell.textLabel.text = cellValue;       
    } else {
        NSArray *sectionArray = [nameStored filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [sections objectAtIndex:indexPath.section]]];
        NSString *temp = [sectionArray objectAtIndex:indexPath.row];
        cell.textLabel.text = temp;
       
        //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        //cell.accessoryType = UITableViewCellAccessoryCheckmark;
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }   
    return cell;
   
}

Sunday, 18 December 2011

Retreiving Multiple strings Saved in an array one by one-iPhone

// in view did load(See Previuos post for Saving)

amountSpend = [[NSMutableArray alloc]init];

NSArray *path1 = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory1 = [path1 objectAtIndex:0];

NSString *fullFileName2 = [NSString stringWithFormat:@"%@amountSpend", documentsDirectory1];
amountSpend=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName2];


NSLog(@"amountSpend array%@",amountSpend);

//display the data where needed.

label.text = [amountSpend objectAtIndex:indexPath.row];

Adding multiple strings in to an array one by one and Saving-iPhone

 //in .h
NSMutableArray *amountSpend;

//in View did load

NSArray *path1 = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory1 = [path1 objectAtIndex:0];
NSString *fullFileName1 = [NSString stringWithFormat:@"%@amountSpend", documentsDirectory1];

amountSpend=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName1];

if([amountSpend count]==0){
amountSpend=[NSMutableArray alloc]init];
}


//action when the data need to be saved

[amountSpend addObject:amount.text];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];


NSString *fullFileName1 = [NSString stringWithFormat:@"%@amountSpend", documentsDirectory];
[amountSpend writeToFile:fullFileName1 atomically:NO];

Thursday, 15 December 2011

Simple Calculator code for iPhone

- (void)viewDidLoad
{
[super viewDidLoad];
 resultText.text=@"0.0";
 // Do any additional setup after loading the view, typically from a nib.
}


-(IBAction)digitPress:(id)sender{

 currentNo=currentNo*10+[sender tag];
 resultText.text=[NSString stringWithFormat:@"%d",currentNo];

}(IBAction)OperatorPress:(id)sender{

 if(currentOpertaion==0){
 result=currentNo;

}else{

 switch (currentOpertaion) {
 case 1:
 result=result+currentNo;
 break;
 case 2:
 result=result-currentNo;
 break;

 default:
 break;
}
}
currentNo=0;
 resultText.text=[NSString stringWithFormat:@"%d",result];
 if([sender tag]==0)result=0;
 currentOpertaion=[sender tag];

}
-(IBAction)clear:(id)sender{
 resultText.text=@"0.0";
 currentNo=0;
 result=0;
}

Wednesday, 14 December 2011

Using NSUserDefaults-iPhone

//Storing
Nsstring *Title;

[[NSUserDefaults standardUserDefaults] setObject:Title forKey:@"token"];

//Retrieving
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"token"]){
tokenStr=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
}

//Removing
NSUserDefaults *myDefault = [NSUserDefaults standardUserDefaults];
[myDefault removeObjectForKey:@"token"];

Pushing Animations In NavigationBased-iPhone

//1)
DemoAppViewController *anotherViewController = [[DemoAppViewController alloc]  initWithNibName:@"DemoAppViewController" bundle:nil];

               anotherViewController.phrase=descri;
       
        [UIView beginAnimations:nil context:NULL];
       
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];



//[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
                           forView:self.navigationController.view cache:NO];
   


[UIView setAnimationDuration:.8];




        [self.navigationController pushViewController:anotherViewController animated:NO];
                [anotherViewController release];
        [UIView commitAnimations];



TableView Usual Code-iPhone

pragma mark Table view methods

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75.0;    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (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] autorelease];
    }
   
    // Configure the cell.
    cell.textLabel.text=@"Hai";
   
   
    return cell;
}




// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   }


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


/*
 // 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:[NSArray arrayWithObject: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;
 }
 */


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

@end

Converting String to Integer and ViceVersa-iPhone

/Converting String in to an Integer.


NSString *myString=@"56";

int value = [myString intValue];

//Converting Integer in to an String.

NSString *newText = [NSString StringWithFormat:@"%d",Value];

Touch Recognition In View-iPhone

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesBegan");
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesMoved");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded");
}

Image Saving In an Array 1 by 1 and Retrieving-iPhone

image saving to an array 1 by 1 and retrieving.

//Adding.

- (void)viewDidLoad {
    [super viewDidLoad];

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
    imageArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName];
   
   
    if([imageArray count]==0){
        imageArray=[[NSMutableArray alloc]init];
       
    }
}

-(IBAction)done:(id)sender{

NSData *ImageData1 = UIImageJPEGRepresentation(imageView.image, 0.9);
    [imageArray addObject:ImageData1];
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
    [imageArray writeToFile:fullFileName atomically:NO];
   
   
    NSLog(@"count==%d",[imageArray count]);
   // NSLog(@"%@",imageArray);
    [self.navigationController popViewControllerAnimated:YES];
}

//Retrieving

scrollPages=[[NSMutableArray alloc]init];
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
    scrollPages=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName];
   
    NSLog(@"scrollcount%d",[scrollPages count]);
}


//where to display

   
    NSData *imgData = (NSData*)[scrollPages objectAtIndex:index];
   
    UIImage* imge = [[UIImage alloc] initWithData:imgData];
   // img.image=imge;
   
    imageView.image = imge;

WebView BackGround Image-iPhone

[webView setOpaque:NO];
     webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"news00.jpg"]];

WebView Loading-iPhone

//At .h

@interface MyWebViewController : UIViewController {
    IBOutlet UIWebView *webView;
    IBOutlet UIActivityIndicatorView *activ;
}
@property (nonatomic,retain) UIWebView *webView;
@property (nonatomic,retain) UIActivityIndicatorView *activ;

-(IBAction)goBack:(id)sender;
-(IBAction)goForward:(id)sender;
@end


 At .m

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *urlAddress=@"http://icodeblog.com";
   
    NSURL *url=[NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
   
    [webView loadRequest:requestObj];
   
   
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
    [activ startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [activ stopAnimating];
    //self.activ=nil;
}


-(IBAction)goBack:(id)sender{

    [webView goBack];
}

-(IBAction)goForward:(id)sender{
    [webView goForward];
}

DidSelectRow code Table View-iPhone

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    if(indexPath.section==0)
    {
LiveScoreViewController *detailViewController = [[LiveScoreViewController alloc] initWithNibName:@"LiveScoreViewController" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

}
}

Removing Blue blink of Table view while touch-iPhone

 At did select row

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

CReating a Slider(UI Object) in table view Cell-iPhone

- (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] autorelease];
    }
   
   
    theSlider =  [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
    theSlider.maximumValue=99;
    theSlider.minimumValue=0;
    [cell addSubview:theSlider];
    cell.accessoryView = theSlider;   
   
    [(UISlider *)cell.accessoryView addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
    //[cell.contentView addSubview:[[sliders objectAtIndex:indexPath.section] objectForKey:@"Red"]];
    //[cell.contentView addSubview:[[UISlider objectAtIndex:indexPath.section] objectForKey:@"Red"]];
    // Configure the cell.
    //cell.textLabel.text=@"Hai";
   
   
    return cell;
}

- (void)sliderValueChange:(id)sender{
   
}

Pushing a View basedApplication-iPhone

 DetailView *anotherViewController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
[self presentModalViewController:anotherViewController animated:YES];
[anotherViewController release];

Pushing a navigation View-iPhone

DetailView *anotherViewController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];

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

 [anotherViewController release];

Network Indicator-iPhone

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;


or custom as

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    indicator.hidesWhenStopped = YES;
    [indicator stopAnimating];
// [indicator startAnimating];
    self.activityIndicator = indicator;
    [indicator release];
   
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:indicator];
    self.navigationItem.rightBarButtonItem = rightButton;
    [rightButton release];

Disclosure indicators in Table vIew-iPhone

cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
    //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    //cell.accessoryType = UITableViewCellAccessoryCheckmark;

 return cell;

or custom image as

UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
        cell.accessoryView =
            [[[UIImageView alloc]
                initWithImage:indicatorImage]
            autorelease];

Titles of Header,Footer and Index and Indent in Table view-iPhone

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"Section title";
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
    return @"Footer title";
}



- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    NSMutableArray *index = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",@"D",nil];
    return index;
}


- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) return 2;
    return 0;
}

Adding Header and Footer in Table View-iPhone

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

No of Sections,Rows and Height of Header,footer,Row of Table View-iPhone

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


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

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return 80;
    return 15;
}


-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 25.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75.0;   
}

Custom Cell Code-iPhone

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

static NSString *cellID= @"catogoryCell";
    CustomCatogory *cell = (CustomCatogory *)[tableView dequeueReusableCellWithIdentifier:cellID];
   
    if(cell==nil)
    {
       
       
        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCatogory" owner:nil options:nil];
       
        for(id currentObject in nibObjects)
        {
            if([currentObject isKindOfClass: [CustomCatogory class]])
            {
                cell = (CustomCatogory *)currentObject;
            }
           
        }
    }
    cell.img1.image=[UIImage imageNamed:@"Tweet1.jpg"];
    cell.title1.text = [categoryList objectAtIndex:indexPath.section] ;
   
   
   
    return cell;
}

Back button code in Navigation bar-iPhone

UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
    temporaryBarButtonItem.title = @"Back";
    self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    [temporaryBarButtonItem release];

Alert View and Dismiss with button index-iPhone

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Wrong Answer.." message:@"SORRY..!!!" delegate:self cancelButtonTitle:@"Next Question" otherButtonTitles:nil,nil];
        [alert show];
        [alert release];



- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
   
    // The first button (or cancel button)
    if (buttonIndex == 0) {
       
        NSLog(@"%@ Pressed cancel", [alertView buttonTitleAtIndex:0]);
       
        [self.navigationController popViewControllerAnimated:YES];
    }   
   
    // The second button on the alert view
    if (buttonIndex == 1) {
       
        NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/iratedphrase/id431595350?mt=8&ls=1"];
       
        if (![[UIApplication sharedApplication] openURL:url])
           
            NSLog(@"%@%@",@"Failed to open url:",[url description]);
    }
   
}

Adding objects in to an array and displaying it in a table view cell-iPhone

- (void)viewDidLoad {
    [super viewDidLoad];

array1 =[[NSMutableArray alloc]initWithObjects:@"Sources of Stress",@"Stress Symptoms",@"Stress Resilience",nil];
array2 =[[NSMutableArray alloc]initWithObjects:@"Mood",@"Notes",nil];

}

//In side the cellfor row at indexpath

f(indexPath.section==0)
    {
        //cell.textLabel.textAlignment=UITextAlignmentCenter;
        cell.textLabel.text=[array1 objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else
    {
        //cell.textLabel.textAlignment=UITextAlignmentCenter;
        cell.textLabel.text=[array2 objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }
    return cell;



Action Sheet Code and Dismiss with buttonIndex-iPhone

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Facebook?"
                                                             delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"OK" otherButtonTitles:nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showFromTabBar:self.tabBarController.tabBar];
    [actionSheet release];  


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex==0){
        [self sendMail];
    }
    else if(buttonIndex == 1){
       
        NSLog(@"CLLLLL");

}
}

Adding a right Button to navigation bar-iPhone

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(openWebLink:)];

//method
-(void)openWebLink:(id) sender{

// code
}

Sunday, 5 June 2011

Welcome EveryBody!!

Here I would like to Share the knowledge of mine in iPhone Coding To Everyone. Expecting your cooperation. Thanks and Regards!!