Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITextField不是';行不通_Iphone_Objective C_Xcode_Ios4_Uitextfield - Fatal编程技术网

Iphone UITextField不是';行不通

Iphone UITextField不是';行不通,iphone,objective-c,xcode,ios4,uitextfield,Iphone,Objective C,Xcode,Ios4,Uitextfield,我是objective-c编程新手,如果这是一个愚蠢的问题,很抱歉,但我仔细查看了一遍,没有发现错误, p、 s:英语不是我的第一语言,所以可能会无意中使用编程关键词 我已经设置了一个txtfield并定义了它的一些属性,比如键盘数字键盘等等,问题是,当我在模拟器上运行它时,什么都没有发生,defult键盘被调用 我只是想做些简单的事情让它进入我的脑海, 在我的.h中,我有 @interface practiceViewController : UIViewController <UITe

我是objective-c编程新手,如果这是一个愚蠢的问题,很抱歉,但我仔细查看了一遍,没有发现错误, p、 s:英语不是我的第一语言,所以可能会无意中使用编程关键词

我已经设置了一个txtfield并定义了它的一些属性,比如键盘数字键盘等等,问题是,当我在模拟器上运行它时,什么都没有发生,defult键盘被调用

我只是想做些简单的事情让它进入我的脑海, 在我的.h中,我有

@interface practiceViewController : UIViewController <UITextFieldDelegate>
{
    UITextField *userInput;
}
@property (nonatomic, retain, readwrite) UITextField *userInput;
@end
}

我也试着把它作为输入,但出于某种原因,它不起作用

int nInput=[[userInput text] intValue];
让我恼火的是,我在以前的项目中也做了同样的事情,只是“输入有效”,但现在一切都不起作用了。 还有我的财产,因为我没有定义任何东西。
我感谢你的帮助

虽然事情不太明朗,但

您正在使用

int nInput = [[userInput text] intValue];
如果没有得到正确的值,则
nInput
将为零。这是因为
userInput
必须是
nil
。您可以通过添加
NSLog(@“%@”,userInput)来记录来验证这一点在上面一行之前

无论打印的值是什么,屏幕上的文本字段似乎没有被
userInput
引用

由于您以编程方式完成了整个过程,因此必须通过这样做将
userInput
添加到视图层次结构中

[self.view addSubview:self.userInput];

使用属性访问器在这里很重要,否则
userInput
将是
nil
,除非您之前使用
self.userInput
访问它。

虽然这是标记为iPhone的,但您是否碰巧在模拟iPad?如果是这样的话,我就遇到了这个问题。iPad不会显示数字键盘。

我想你必须像这样设置UITextField的框架

userInput.frame=CGRectMake(100,100,60,31);
在您的-(UITextField*)用户输入方法中,它没有显示

userInput= [[UITextField alloc] initWithFrame:CGRectMake(10, 50, 200, 30)]
userInput.keyboardType= UIKeyboardTypeNumberPad;
userInput.returnKeyType= UIReturnKeyDone;
userInput.textColor=[ UIColor redColor];
userInput.clearButtonMode= UITextFieldViewModeWhileEditing;
userInput.delegate = self;
您只需设置框架并添加以下属性(以使textfield框架在视图中可见,否则它在视图中不可见)


我希望它会对您有所帮助。

您是否将其添加为子视图?否,我仅使用单个视图您是否在IB中添加UITextField对象?我忘记了,thx很多,这是用于输入部分的,但我仍然有默认键盘,并且没有任何属性正在工作您正在以编程方式创建它,你不需要在IB中再次使用它。我可能做得不对,似乎每次我删除IB时,文本字段对输入没有反应,我试图添加它,但要么不知道它是如何工作的,要么它不工作,因为它不工作,顺便说一句,但我的主要问题是我无法控制这个txtfield的比例,例如键盘类型,和“完成”按钮等,你可以找出错误。
userInput= [[UITextField alloc] initWithFrame:CGRectMake(10, 50, 200, 30)]
userInput.keyboardType= UIKeyboardTypeNumberPad;
userInput.returnKeyType= UIReturnKeyDone;
userInput.textColor=[ UIColor redColor];
userInput.clearButtonMode= UITextFieldViewModeWhileEditing;
userInput.delegate = self;
  userInput.borderStyle = UITextBorderStyleRoundedRect;
 [self.view addSubview:userInput];