调整页脚视图高度使UITableView略微移动

时间:2018-06-06 03:34:29

标签: ios swift uitableview

在我的应用程序中,我的页脚高度为零。当某个动作发生时,我想增加页脚视图的高度,例如当出现提交按钮时:

 /*
 * Hangman 
     * 5/23/18
     * JDK Version 1.8.0
     */
    package hangman;

    import java.awt.*;
    import java.util.Scanner;
    import javax.swing.*;

    public class PlayHangman {

        public static void main(String[] args) {
            Hangman hangman = new Hangman();
            Scanner scn = new Scanner(System.in);
            int triesCount = 0;
            int correctCount = 0;
            int triesLimit = 7;
            hangman.setWord();
            String secretWord = hangman.getWord();
            int winCount = secretWord.length();
            StringBuilder b = new StringBuilder(secretWord.length());
            for (int i = 0; i < secretWord.length(); i++) {
                b.append("*");
            }
            char[] secrectStrCharArr = secretWord.toCharArray();
            int charCnt = secretWord.length();
            for (int x = 0; triesCount < triesLimit; x++) {

                    System.out.println("Secrect Word :" + b.toString());
                    System.out.println("Guess a letter :");

                    char guessChar = scn.next().toCharArray()[0];
                    for (int i = 0; i < secrectStrCharArr.length; i++) {
                        if(correctCount == winCount)
                        {System.out.println("Congrats! You have won!");}    
                        else if (guessChar == secrectStrCharArr[i]) {
                            b.setCharAt(i, guessChar);
                            correctCount++;hangmanImage(triesCount,correctCount);
                        } else if (guessChar != secrectStrCharArr[i]) {
                            triesCount++;
                            System.out.println("Incorrect: " + triesCount);
                            hangmanImage(triesCount, correctCount);
                        }

                    }
            }
        }

        public static void hangmanImage(int triesCount, int correctCount) {

          if (triesCount == 1) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" |Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |                      ");
                    System.out.println("   |                        ");
                    System.out.println("   |                       ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");


                }
            if (triesCount == 2) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" | Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |            |               ");
                    System.out.println("   |            |                ");
                    System.out.println("   |            |               ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");


                }
            if (triesCount == 3) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" | Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |            |   /            ");
                    System.out.println("   |            | -/               ");
                    System.out.println("   |            |               ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");


                }
                if (triesCount == 4) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" | Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |            |   /             ");
                    System.out.println("   |            | -/                ");
                    System.out.println("   |            |               ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");


                }
                if (triesCount == 5) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" |Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |      \\    |   /            ");
                    System.out.println("   |        \\- | -/               ");
                    System.out.println("   |            |               ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");
                    System.out.println("   |                           ");


                }
                if (triesCount == 6) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" |Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |      \\    |   /            ");
                    System.out.println("   |        \\- | -/               ");
                    System.out.println("   |            |               ");
                    System.out.println("   |             \\               ");
                    System.out.println("   |               \\             ");
                    System.out.println("   |                 --          ");


                }

                if (triesCount == 7) {
                    System.out.println("Wrong guess, try again - Incorrect: " + triesCount+" |Correct: "+correctCount);
                    System.out.println("   ____________");
                    System.out.println("   |          _|_");
                    System.out.println("   |         /   \\");
                    System.out.println("   |        |     |");
                    System.out.println("   |         \\_ _/");
                    System.out.println("   |      \\    |   /            ");
                    System.out.println("   |        \\- | -/               ");
                    System.out.println("   |            |               ");
                    System.out.println("   |           /  \\               ");
                    System.out.println("   |          /     \\             ");
                    System.out.println("   |       ---        ---          ");


                }

                if(triesCount>7)
                {System.out.println("You lost");}


        }

    }

我只需将func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { if isShowingSubmitButton { return 72.0 } else { return 0 } } 设置为true,然后重新加载tableview。这工作正常但是当我重新加载表时,表格会略微滚动/移动。我需要桌子保持静止而不动。我在这里做错了什么?

0 个答案:

没有答案