彻底解雇SKScene

时间:2017-02-05 16:21:53

标签: swift uiviewcontroller skscene dismiss

好吧所以我有一个应用程序,从菜单视图控制器开始,提示用户按下4个按钮之一,然后加载一个视图控制器,然后呈现一个场景,用户根据按下哪个按钮来玩游戏。 / p>

然后我将用户重定向到另一个视图控制器,一旦满足条件(他们输掉游戏),它就呈现另一个场景。唯一的问题是,第二个视图控制器(我假设它的场景)仍然在运行。我知道这是因为我在其中有一个打印声明覆盖函数更新方法,看看它是否还在那里。

另外,我在我的旧游戏中播放音频,但它目前还在播放。我不会完全记住,因为稍后我会在所有3个视图控制器和它们呈现的场景之间传递音频数据(全部静音)。

现在正在发生的事情的唯一问题是,当我运行应用程序时,因为旧的viewiewcontroller它的场景似乎仍然在下面运行,它一直调用过渡,这导致一个奇怪的外观,当条件满足,转换循环到新的viewcontroller,然后回到转换的开始,然后再次循环到新的viewcontroller。

我已尝试过这段代码:

let theVC = self.viewController?.storyboard?.instantiateViewController(withIdentifier: "TrumpVC") as! TrumpViewController

self.viewController?.navigationController?.pushViewController(theVC, animated: true)

self.viewController?.dismiss(animated: true, completion: {});

但它似乎没有任何帮助:(基本上我导航到一个新的viewcontroller并解除当前的一个(这在我的场景中都是这样)

由于

1 个答案:

答案 0 :(得分:0)

解决方案:

class ProductionsController < ApplicationController
  before_action :authenticate_user! 
  skip_before_action :configure_sign_up_params
  before_action :set_ranch
  before_action :set_production, except: [:create, :new, :show]
  before_action :set_production2, only: [:show]

  # GET /productions
  # GET /productions.json
  def index
    @productions = Production.all
  end

  # GET /productions/1
  # GET /productions/1.json
  def show
    @iproductions = Iproduction.where(id: params[:production_id])
  end

  # GET /productions/new
  def new
    @production = @ranch.productions.build
    @cows = @ranch.cows
  end

  # GET /productions/1/edit
  def edit
    @cows = @ranch.cows
  end

  # POST /productions
  # POST /productions.json
  def create
    @production = @ranch.productions.create(production_params)
    @production.update(date: Date.today)
    @cows = @ranch.cows
    respond_to do |format|
      if @production.save
        format.html { redirect_to ranch_production_path(@production.ranch_id, @production), notice: 'Production was successfully created.' }
        format.json { render :show, status: :created, location: @production }
      else
        format.html { render :new }
        format.json { render json: @production.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /productions/1
  # PATCH/PUT /productions/1.json
  def update
    respond_to do |format|
      if @production.update(production_params)
        format.html { redirect_to ranch_production_path(@production.ranch_id, @production), notice: 'Production was successfully updated.' }
        format.json { render :show, status: :ok, location: @production }
      else
        format.html { render :edit }
        format.json { render json: @production.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /productions/1
  # DELETE /productions/1.json
  def destroy
    @production.destroy
    respond_to do |format|
      format.html { redirect_to ranch_productions_path(@production.ranch_id), notice: 'Production was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.

    def set_ranch 
      @ranch = Ranch.find(params[:ranch_id])
    end 

    def set_production2 
      @production = Production.find_by(id: params[:id])
    end 

    def set_production 
      @production = @ranch.productions.find_by(id: params[:id])
    end 

    # Never trust parameters from the scary internet, only allow the white list through.
    def production_params
      params.require(:production).permit(:name, :ranch_id, :created_at, :date, iproductions_attributes: [:id, :date, :cow_id, :quantity, :_destroy])
    end
end