开发者

checking if a textfield is null

I currently add objects to an array with a label taken from the textfield input from the user.

At the moment it adds an entry even if the field is blank.

I assign the textfield to a string and then want to check if it is nil, if it is then dont add it to the array.

I am used to java where it could be done with something like

if(enteredText.length > 0){ //add to array}

I am trying the following in my code now

if(title != nil)
{
[plistArray addObject:title];
[plistArray writeToFile:filepath atomically: YES];
}

but it doesnt seem to work and there are no dot methods available开发者_StackOverflow社区 to get the length of the entered text.

How could I achieve this in Obj-C?

Regards


Use the -length method of NSString

if(title != nil && [title length])
{
    [plistArray addObject:title];
    [plistArray writeToFile:filepath atomically: YES];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜