如何在xcode的IOS打印字符串的UITextField

问题描述:

我米具有移动号码,这是在该程序保存在的NSString变量,我想,当用户进入的窗口在一个的UITextField显示用户详细信息在我的iOS应用程序。我也想禁用电话号码的编辑。我怎样才能做到这一点?即时通讯使用的Xcode 7.4.2如何在xcode的IOS打印字符串的UITextField

+0

可以显示已尝试的代码 –

+0

您可以使用print函数打印textFieldData print(usertextfiledname.text)并禁用textField yourtextFileldname.userInterface = false – iParesh

+0

对不起,我还没有尝试过任何东西。我新这个iOS应用程序开发。 –

初步检查您的字符串包含值或不和不喜欢

yourMobileNumberTextfield.userInteractionEnabled = true; 
if (yourString.length > 0) 
{ 
yourMobileNumberTextfield.text = yourString; 
yourMobileNumberTextfield.userInteractionEnabled = false; 
} 

斯威夫特

yourMobileNumberTextfield.userInteractionEnabled = true 
if yourString.length > 0 { 
yourMobileNumberTextfield.text = yourString 
yourMobileNumberTextfield.userInteractionEnabled = false 
} 

更新

为保持前值在你的应用程序,然后去NSUserDefault,

第1步,当你的OTP验证成功保存当前手机号码的UserDefaults

[[NSUserDefaults standardUserDefaults] setObject:yourMobileNumberTextfield.text forKey:@"Mobile"]; 

步骤2

如果第二时间用户进入页面上

你需要打电话像

NSString *savedValue = [[NSUserDefaults standardUserDefaults] 
stringForKey:@"Mobile"]; 

yourMobileNumberTextfield.userInteractionEnabled = true; 
if (savedValue.length > 0) 
{ 
yourMobileNumberTextfield.text = savedValue; 
yourMobileNumberTextfield.userInteractionEnabled = false; 
} 

斯威夫特

保存

 NSUserDefaults.standardUserDefaults().setObject(yourMobileNumberTextfield.text, forKey: "Mobile") 

检索

let savedValue = NSUserDefaults.standardUserDefaults().stringForKey("Mobile")! 
yourMobileNumberTextfield.userInteractionEnabled = true 
if savedValue.length > 0 { 
yourMobileNumberTextfield.text = savedValue 
yourMobileNumberTextfield.userInteractionEnabled = false 
} 
+0

好吧,我会尝试,并更新结果。 –

+0

@SHAHALNS - 检查更新后的答案 –

+0

if循环中的第一行显示警告,即:yourMobileNumberTextfield.text = yourString;显示警告“不兼容的指针类型分配给NSString * _Nullable从'UITextField'” –

获取手机号码到文本字段

NSString *strMobileNo = @"036467345672"; //Give your no here 
yourTextFieldName.text = strMobileNo; 
    //OR 
yourTextFieldName.text = [NSString stringWithFormat:@"036467345672"]; 
    //OR 
yourTextFieldName.text = @"036467345672"; 

禁用文本框编辑

yourTextFieldName.enabled = NO; 
+0

if循环内的第一行显示警告,即:yourMobileNumberTextfield .text = yourString;显示警告:“不兼容的指针类型分配给NSString * _Nullable来自'UITextField'” –

+0

给你的文本字段和字符串名称,以及如何获得移动的否字符串? – user3182143

+0

什么是textField名称? – user3182143

如果的UITextField名称是“文本框”,并具有u的NSString变量是“手机”。

textField.text=phone; 
textField.enabled=true; 

我宁愿使用UILabel来代替,如果您需要这两件事情来完成。它默认是不能编辑的。

+0

if循环内的第一行显示警告,即:yourMobileNumberTextfield.text = yourString;显示警告:“不兼容的指针类型分配给NSString * _Nullable来自'UITextField'” –

+0

尝试'[self textField] = phone;'或'_textField.text = phone;' – Saranjith

+0

@SHAHAL检查可变电话是否为NSString类型 – Saranjith