私は uitextfield を持っています。それが初期化され、それに値を入力しなかった場合、uitextfield の値が null でも nil でもないことがわかりました。
NSString *notes = (notesField.text)?(notesField.text):@"hello";
NSLog(@"notes: %@",notes);
メモには何も返さない
NSString *notes1;
//or use legnth
if ([notesField.text isEqual:@""]) {
notes1=@"hello";
NSLog(@"empty textfield: %@",notes1);
//then it returns "hello"
}
else
{
notes1=notesField.text;
NSLog(@"not empty textfield: %@",notes1);
}
何故ですか?まだ三項演算子を使用できますか? このような ?
NSString *notes = ([notesField.text length])?(notesField.text):@"hello";