1

左側に固定ラベルを含み、各セルに UITextField を含む非常に単純な UITableView があります。デバイスが回転したときにセルの幅を拡大および縮小するには、uitextfield が必要です。設定してみました

autoresizedSubviews = YES; autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

テーブルビュー、セル、および cell.contentView の場合、それらのどれも textField に影響を与えないようです。

そして、実際の textField の autoresizingMask を flexibleWidth と FlexibleRightMargin に設定すると、textField は画面の向きに関係なく画面からはみ出してしまいます。

textField を作成してセルに追加するコードは次のとおりです。

    int marginBetweenCellAndScreenEdge;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    marginBetweenCellAndScreenEdge = 44;
} else {
    marginBetweenCellAndScreenEdge = 10;
}

float viewWidth = self.parentViewController.view.bounds.size.width;
int textFieldWidth = viewWidth - (2*marginBetweenCellAndScreenEdge) - 75 - 20;
NSLog(@"%d", textFieldWidth);

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, textFieldWidth, 25)];
textField.clearsOnBeginEditing = NO;
[textField setDelegate:self];
textField.returnKeyType = UIReturnKeyDone;
textField.tag = kTextFieldTag;

textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;


//make it so that the UITextField subview resigns the firstresponder (keyboard) when done editing
[textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];

[cell.contentView addSubview:textField];

どんな助けでも大歓迎です!! ありがとう!!

4

0 に答える 0