您的位置:首页 > 移动开发 > IOS开发

ios的计算字符串的长度

2013-05-15 16:01 405 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: