解雇Popover

时间:2017-03-08 00:58:53

标签: ios swift3

我从第一个视图控制器(tableview)到第二个视图控制器,它是一个tableview。在我不使用第二个视图后,我需要在第一个控制器中重新加载表视图。 popoverPresentationControllerDidDismissPopover如果我在弹出窗口外点击会被调用,但如果第二个tableview中有另一个按钮又回到第一个按钮会怎么样? 通常我需要用户点击“添加”按钮以退出桌面视图,而不是点击弹出窗口外部。我保留外部点击作为取消操作。

谢谢 Poppver on top of a tableview

2 个答案:

答案 0 :(得分:3)

当您以编程方式解除委托方法时,不会调用委托方法memory out of heap!

解决方案是当您通过调用//webpack.config.js var webpack = require("webpack"); var path = require("path"); var glob = require('glob'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var entries = getEntry('src/Html/**/*.js', 'src/Html/'); entries['index'] = './src/app.js'; var config = { devtool: 'source-map', entry: entries, output: { path: "dist", filename: "js/[name].js", chunkFilename: "js/[name].js" }, module: { loaders:[ { test: require.resolve('jquery'), loader: 'expose?jQuery!expose?$' }, { test: /\.js[x]?$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' },{ test: /\.css$/, loader: 'style-loader!css-loader' },{ test: /\.less/, loader: 'style-loader!css-loader!less-loader' }, { test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192&name=img/[hash].[ext]' } ] }, plugins:[ new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), new webpack.optimize.UglifyJsPlugin({ sourceMap: false, mangle: false }), new webpack.DefinePlugin({ 'process.env': {NODE_ENV: JSON.stringify("production")} }), new webpack.ProvidePlugin({ $:"jquery", jQuery:"jquery", "window.jQuery":"jquery" }) ], resolve: { alias: { jquery: "jquery/src/jquery" } }, babel:{ plugins:[["import", [{ "libraryName": "antd", "style": "css" }]]] }, externals: { jquery: 'window.$', artTemplate: 'window.template' }, devServer: { contentBase: "./", // colors: true, // historyApiFallback: true, // inline: true, // port: 8205 }, }; var pages = getEntry('src/Html/**/*.html', 'src/Html/'); var pagenames = Object.keys(pages); config.plugins.push(new HtmlWebpackPlugin({ filename: './index.html', template: './src/index.html', inject: true, chunks: ['index'], hash: true, minify: { removeComments: true, collapseWhitespace: false } })); pagenames.forEach(function (pagename) { var conf = { filename: './pages/' + pagename + '.html', template: pages[pagename], inject: 'body', minify: { removeComments: true, collapseWhitespace: false } }; if (pagename in config.entry) { conf.inject = true; conf.chunks = [pagename]; conf.hash = true; } config.plugins.push(new HtmlWebpackPlugin(conf)); }); function getEntry(globPath, pathDir) { var files = glob.sync(globPath); var entries = {}, entry, dirname, basename, pathname, extname; for (var i = 0; i < files.length; i++) { entry = files[i]; dirname = path.dirname(entry); extname = path.extname(entry); basename = path.basename(entry, extname); pathname = path.join(dirname, basename); pathname = pathDir ? pathname.replace(new RegExp('^' + pathDir), '') : pathname; entries[basename] = './' + entry; } return entries; } module.exports = config; //================================================================= //-------- package.json { "private": true, "entry": { "index": "./src/index.js" }, "dependencies": { "antd": "^2.1.0", "react": "^15.1.0", "react-dom": "^15.1.0", "react-router": "^3.0.0", "react-redux": "^4.4.5", "redux": "^3.6.0", "redux-thunk":"2.1.0" }, "devDependencies": { "atool-build": "^0.9.0", "atool-test-mocha": "^0.1.4", "babel-eslint": "^7.0.0", "babel-plugin-import": "^1.0.1", "babel-plugin-transform-runtime": "^6.8.0", "babel-runtime": "^6.9.2", "babel-loader": "^6.2.5", "babel-plugin-transform-runtime": "^6.15.0", "babel-preset-es2015": "^6.14.0", "babel-preset-react": "^6.11.1", "babel-preset-stage-0": "^6.3.13", "babel-runtime": "^6.11.6", "better-npm-run": "0.0.11", "css-loader": "^0.25.0", "sass-loader": "^4.0.0", "style-loader": "^0.13.1", "url-loader": "^0.5.6", "cssnano": "^3.7.4", "debug": "^2.2.0", "extract-text-webpack-plugin": "^1.0.0", "file-loader": "^0.9.0", "eslint": "^3.8.1", "eslint-config-airbnb": "^12.0.0", "eslint-plugin-import": "^2.0.1", "eslint-plugin-jsx-a11y": "^2.2.3", "eslint-plugin-react": "^6.4.1", "expect": "^1.20.1", "jquery": "^3.1.1", "pre-commit": "1.x", "redbox-react": "^1.2.6", "webpack-dev-server": "^1.16.2", "webpack": "^1.12.14", "webpack-dev-middleware": "^1.6.1", "webpack-hot-middleware": "^2.12.2", "extract-text-webpack-plugin": "^1.0.1", "html-webpack-plugin": "^2.22.0", "glob": "^7.0.6" }, "pre-commit": [ "lint" ], "scripts": { "build": "webpack", "lint": "eslint --ext .js,.jsx src/", "start": "webpack-dev-server --inline", "test": "atool-test-mocha ./**/__tests__/*-test.js", "dev": "webpack-dev-server --devtool eval --progress --colors --hot -- content-base build" } } 来解除弹出窗口时,您必须调用表视图来重新加载数据。

所以基本上你打两次popoverPresentationControllerDidDismissPopover。一个位于dismiss(animated:completion:),一个位于tableView.reloadData()之后,位于添加按钮的方法中。

<强>更新

从你的截图中,我假设你的第一个视图控制器(VC1)是背景视图,第二个视图控制器(VC2)是弹出窗口。

如果是这样,您有两种选择:

  1. 在VC2上,声明自定义协议以通知VC1重新加载表 每当选择一行时查看数据,并将VC1中的委托设置为VC2。
  2. 您可以在VC2中简单地声明一个块属性,而不是使用协议。例如:

    popoverPresentationControllerDidDismissPopover;

  3. 当选择某个项目时,请调用此方法(仍在VC2中):

    dismiss(animated:completion:)

    然后在VC1中,在初始化VC2(即弹出窗口)后,处理该块。例如:

    @property (copy, nonatomic) void (^itemSelectedHandler)()

    不幸的是,我没有快速编程的经验,所以我必须使用客观的c代码作为例子。

答案 1 :(得分:0)

Swift 3.0版本:

Popover VC:

定义属性:

var dismissHandler: (() -> Void)!

在解除弹出窗口时调用此处理程序:

self.dismissHandler()

家长VC:

在Segue的准备方法中传递处理程序

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    ...
    destinationVC.dismissHandler = {
        self.tableView.reloadData()
    }
    ...
}