UITextFielda の中に aを入れて実験していUITableViewCellます。
これで、2 つの作業方法が得られました。
使用addSubview方法:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(150, 7, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell addSubview:textFieldView];
使用setAccessoryView方法:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell setAccessoryView:textFieldView];
私の意見ではsetAccessoryView、位置合わせが自動的に行われるため、結果の見栄えが良くなります。
しかし、私の質問は次のとおりUITextFieldですAccessoryView。それとも、そのようにしてはいけない正当な理由がありますか?