ios的计算字符串的长度

1.

lengthViewController.h

import


@interface lengthViewController : UIViewController{

    IBOutlet UILabel *dispLenLabel;

    IBOutlet  UITextField *inputField;

    

}

-(IBAction)btnDown:(id)sender;



@end

2.

lengthViewController.m


#import "lengthViewController.h"


@implementation lengthViewController


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.

}


#pragma mark - View lifecycle


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}







- (void)viewDidUnload

{

    [super viewDidUnload];

    // Release any retained subviews of the main view.

    // e.g. self.myOutlet = nil;

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

}


- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

}


- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

}


- (void)viewDidDisappear:(BOOL)animated

{

[super viewDidDisappear:animated];

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // Return YES for supported orientations

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

-(IBAction)btnDown:(id)sender{

    int len=inputField.text.length;

    

    if(len){

        //如果不为空

        dispLenLabel.text=[NSString stringWithFormat:@"%d",len];

        

    }else{

        //给出警告

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"错误提示" message:@"请输入内容" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];    

    

        [alert show];

      //  [alert release];

}

}


@end



你可能感兴趣的:(oc)