zoukankan      html  css  js  c++  java
  • IOS控件:计算文字长度(UITextField,UILabel对象 和 IBAction)

    #import <UIKit/UIKit.h>
    
    // UIViewController类为程序提供了基本的视图管理模块
    @interface NavControllerViewController : UIViewController {
        // 此处建立标签显示文字;把所需显示的文字标签告诉Interface Builder
        IBOutlet UILabel *label;
        // 文本框;把所需显示的文字标签告诉Interface Builder
        IBOutlet UITextField *textField;
    }
    // @property 声明程序的属性
    @property(nonatomic, retain) UITextField *textField;
    @property(nonatomic, retain) UILabel *label;
    // 操作效应的方法,单击按钮把文本框输入的文字长度值显示在标签控件上
    -(IBAction)click;
    
    @end
    #import "NavControllerViewController.h"
    
    @interface NavControllerViewController ()
    
    @end
    
    @implementation NavControllerViewController
    
    // 本指令告诉编译器去合成方法所需要的“文本框”和“标签”控件存储方法
    @synthesize textField, label;
    
    -(IBAction)click {
        int textCount = textField.text.length;
        if (textCount > 30) {
            label.text = @"您输入的信息,长度不能超过30个字母。";
            textField.text = NULL;
        }else{
            NSString *result = [NSString stringWithFormat:@"您输入的文字长度为:%d", textCount];
            label.text = result;
            textField.text = NULL;
        }
    }
    
    // 释放方法,执行内存清理工作
    - (void)dealloc{
        [label release];
        [textField release];
        [super dealloc];
    }
    
    - (void)viewDidLoad {
        label.text = @"请输入文字";
        [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.
    }
    
    @end

  • 相关阅读:
    BurpSuite—-Spider模块(蜘蛛爬行)
    BurpSuite系列(一)----Proxy模块(代理模块)
    hadoop HA集群搭建步骤
    HBase详解
    MapReduce两种执行环境介绍:本地测试环境,服务器环境
    HBase性能优化方法总结
    HDFS原理解析
    ZooKeeper 典型应用场景
    Redis总结
    基于Apache Curator框架的ZooKeeper使用详解
  • 原文地址:https://www.cnblogs.com/androidsj/p/3279275.html
Copyright © 2011-2022 走看看