当键盘出现在第一次启动视图时,uitableview将不会滚动。后来它运作正常

时间:2016-11-09 11:34:08

标签: ios objective-c iphone xcode uitableview

当键盘出现时,有许多关于移动<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <body> <div class="container"> <div id="div1"> <h2>Pick your style</h2> <div class="col-md-4"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Simple_triangle.svg/120px-Simple_triangle.svg.png"> <a class="btn btn-primary btn-lg picture-link" href="#div2" role="button" value="casual">Casual &raquo;</a> </div><!--Closes Col-md-4--> <div class="col-md-4"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Simple_triangle.svg/120px-Simple_triangle.svg.png"> <a class="btn btn-primary btn-lg picture-link" href="#div2" role="button" value="street">Street &raquo;</a> </div><!--Closes Col-md-4--> <div class="col-md-4"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Simple_triangle.svg/120px-Simple_triangle.svg.png"> <a class="btn btn-primary btn-lg picture-link" href="#div2" role="button" value="classic">Classic &raquo;</a> </div><!--Closes Col-md-4--> </div><!--Closes div1--> <div id="div2"> <h3>Measurements</h3> <h5>Measurements can be in inches or centimeters, just please notate which you use</h5> <form> Height:<br> <input type="text" name="height" id="height"><br> Neck:<br> <input type="text" name="neck" id="neck"><br> Arms:<br> <input type="text" name="arms" id="arms"><br> Waist:<br> <input type="text" name="waist" id="waist"><br> Legs:<br> <input type="text" name="legs" id="legs"><br> Shoes:<br> <input type="text" name="shoes" id="shoes"><br> Shirt size:<br> <select name="size"> <option value="small" id="small">Small</option> <option value="medium" id="medium">Medium</option> <option value="large" id="large">Large</option> <option value="xlarge" id="xlarge">X-Large</option> <option value="xxlarge" id="xxlarge">XX-Large</option> </select> </form> <a class="btn btn-primary btn-lg" href="#div3" role="button">Next &raquo;</a> </div><!--Closes div2--> <div id="div3"> <h3>Review</h3> <p>Here's the info you gave us, please double check it:</p> <p>Style:<span id="style-d3"></span></p> <p>Height: <span id="height-d3"></span></p> <p>Neck: <span id="neck-d3"></span></p> <p>Arms: <span id="arms-d3"></span></p> <p>Waist: <span id="waist-d3"></span></p> <p>Legs: <span id="legs-d3"></span></p> <p>Shoes: <span id="shoes-d3"></span></p> <p>Shirt size: <span id="size-d3"></span></p> <p>Finally, any notes for our fashion aids?</p> <textarea name="message" rows="10" cols="100"> Any other concerns you have we should know about? Do you have big thighs, long neck, big arms, etc. anything and anything that can help with the fitting of your clothing is extremely helpful! </textarea> <div id="display"> <a class="btn btn-primary btn-lg" href="success.html" role="button">Submit &raquo;</a> </div> </div><!--Closes div3--> </div><!--Closes container--> </body> 的答案,但我的问题有所不同。我可以在键盘出现时移动UITableView,但我遇到的唯一问题是UITableView在我第一次访问视图时不会滚动,但是当我按下后退按钮并重新访问视图时然后它正常工作。我很困惑这是我第一次访问视图时每次都在工作的相同代码。我在xib中使用UITableView。我尝试设置contentInset但没有用。任何帮助都将非常感激。

我发布的图片显示了我面临的问题

enter image description here

以下是我的代码。

UITableView

1 个答案:

答案 0 :(得分:0)

在主线程中运行键盘通知代码解决了我的问题。这有助于我克服这个问题。我认为由于某种原因,当键盘出现时,tableview框架大小没有更新。发布代码以便它可以帮助其他人。

 - (void)keyboardWillShow:(NSNotification *)notification
    {
  dispatch_async(dispatch_get_main_queue(), ^{
        //This code will run in the main thread:

    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect frame = CGRectMake(_chatConversationTableView.frame.origin.x,
                              _chatConversationTableView.frame.origin.y,
                              _chatConversationTableView.frame.size.width,
                              _chatConversationTableView.frame.size.height - size.height);
    _chatConversationTableView.frame = frame;


    CGRect framee = containerView.frame;
    framee.origin.y = self.view.frame.size.height - framee.size.height - size.height;
    containerView.frame = framee;
    [UIView commitAnimations];

        //scroll to bottom of conversation
        [self scrollToBottomOfConversation];


         });
}