ScheduledTimer不会在Swift 5中停止

时间:2019-12-16 15:46:09

标签: swift

我在swift 5中使用了scheduleTimer。但是,如果我转到另一个viewcontroller,则scheduleTimer无法停止。它继续。我已经使用了下面的viewcontroller代码

public class MainActivity extends AppCompatActivity {

    private ScrollView sV;
    private LinearLayout pnl;
    private GridLayout gL;
    private TextView tV;
    private Button btn;
    private EditText eT;

    private void init() {

        sV = new ScrollView(this);
        hsV = new HorizontalScrollView(this);
        pnl = new LinearLayout(this);
        pnl.setOrientation(LinearLayout.VERTICAL);
        gL = new GridLayout(this);
        gL.setColumnCount(2);

        final String[] title = getResources().getStringArray(R.array.title);
        final String[] info = getResources().getStringArray(R.array.info);

        for (int j = 0; j < 2; j++) {

            tV = new TextView(this);
            tV.setText(title[j]);
            tV.setTextSize(20);
            tV.setTypeface(Typeface.DEFAULT_BOLD);
            tV.setTextColor(getResources().getColor(R.color.colorText));
            gL.addView(tV);

        }

        for (int i = 0; i < 15; i++) {

            tV = new TextView(this);
            tV.setText(info[i]);
            tV.setTextSize(20);
            tV.setTextColor(getResources().getColor(R.color.colorText));
            gL.addView(tV);

            eT = new EditText(this);
            eT.setTextSize(20);
            eT.setInputType(InputType.TYPE_CLASS_NUMBER);
            gL.addView(eT);

        }

        btn = new Button(this);
        btn.setText("Save");
        gL.addView(btn);

        pnl.addView(gL);
        sV.addView(pnl);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        setContentView(sV);

    }

}

当我转到花药ViewController时,请帮助停止计划计时器

0 个答案:

没有答案