更改选项卡时以模态显示的ViewController消失

时间:2018-12-08 08:23:33

标签: ios swift

我有一个package com.example.zeeshankhalid.guesstheceleberity; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.concurrent.ExecutionException; public class MainActivity extends AppCompatActivity { public class downloadTask extends AsyncTask<String,Void,String>{ @Override protected String doInBackground(String... urls) { String result=""; URL url; HttpURLConnection httpURLConnection=null; try { url=new URL(urls[0]); httpURLConnection=(HttpURLConnection)url.openConnection(); InputStream inputStream=httpURLConnection.getInputStream(); InputStreamReader inputStreamReader=new InputStreamReader(inputStream); int data=inputStreamReader.read(); while (data != -1){ char current=(char) data; result+=current; data=inputStreamReader.read(); } return result; } catch (Exception e) { e.printStackTrace(); } return null; } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); downloadTask downloadTask=new downloadTask(); String result=null; try { result= downloadTask.execute("https://www.posh24.com/celebrities").get(); Log.i("results",""+ result); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } } ,它在调用UITableViewController时以模态形式显示UIViewController

我的应用程序包装在didSelectRowAt中。

当用户更改标签时,我想关闭UITabBarController

我曾试图像这样在控制器上调用UIViewController,但这是行不通的。

dismiss

1 个答案:

答案 0 :(得分:1)

将您的解除呼叫置于VimeoController控制器的viewDidDisappear生命周期挂钩中。

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    dismiss(animated: true, completion: nil)
}