入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

ios的计算字符串的长度

创建时间:2013-05-15 投稿人: 浏览次数:1187

1.

lengthViewController.h

import <UIKit/UIKit.h>


@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



声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像