私はIOS開発に不慣れです。写真のようなビューを作成したい。
また、ユーザーがテキストフィールドに書き込み、キーボードが表示されたら、TextFieldがキーボードまでスクロールアップし、キーボードの後ろに隠れるようにします。
ありがとう、助けてください
私はIOS開発に不慣れです。写真のようなビューを作成したい。
また、ユーザーがテキストフィールドに書き込み、キーボードが表示されたら、TextFieldがキーボードまでスクロールアップし、キーボードの後ろに隠れるようにします。
ありがとう、助けてください
フッター内にテキストフィールドとボタンを追加することをお勧めします。キーボード通知を使用してビューオフセットを移動し、ユーザーがキーボードを入力しているときにテキストフィールドが表示されるようにすることができます。
フッター:*テキストフィールドと送信ボタンはivarsであると想定しています。
// add footer to table
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 85.0f)];
if(yourTextField ==nil){
yourTextField = [[UITextField alloc] initWithFrame:CGRectMake(5,5,200,35)];
}
if(yourSendButton ==nil){
yourSendButton = [[UIButton alloc] initWithFrame:CGRectMake(225,5,75,35)];
yourSendButton addTarget:self action:@selector(sendBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
[footerView addSubview:yourTextField];
[footerView addSubview:yourSendButton];
[tableView setTableFooterView:footerView];
キーボードのビューを移動するためのサンプルコードを次に示します。
- (void)keyboardWillShow:(NSNotification *)notification
{
NSValue *keyboardFrameValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrame = [[self view] convertRect:[keyboardFrameValue CGRectValue] fromView:nil];
NSNumber *duration = [[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:[duration floatValue] animations:^{
[scrollView setFrame:CGRectMake(scrollView.frame.origin.x,
scrollView.frame.origin.y,
scrollView.frame.size.width,
keyboardFrame.origin.y - scrollView.frame.origin.y)];
}];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSNumber *duration = [[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:[duration floatValue] animations:^{
[scrollView setFrame:CGRectMake(scrollView.frame.origin.x,
scrollView.frame.origin.y,
scrollView.frame.size.width,
self.view.frame.size.height - (iPhone ? 44.0f : 0.0f))];
}];
}
UITableViewのデリゲートメソッドを実装する必要があります。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
フッターにテキストフィールドを追加する例は、次のようになります。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
{
UIView* footer = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
footer.backgroundColor = [UIColor whiteColor];
UITextField* field = [[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
[field setBorderStyle:UITextBorderStyleBezel];
[footer addSubview:field];
return footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
{
return 44;
}
キーボードを取得するには、自動的に正しく応答します。使い終わったら、テキストフィールドを辞任するだけです。
UITableViewController
標準のViewControllerを使用して、のような必要なデリゲートメソッドをコントローラーに実装UITableViewDelegate
および実装することはできません。UITableViewDataSource
cellForRowAtIndexPath
これにより、テーブルビューを使用して、と同じようにテーブルビューを制御し、UITableViewController
必要な他のインターフェイス要素を使用できるようになります。