假设我有3个视图控制器:A,B和C.并且我有3个段:A-> B,B-> C,C-> B。 我正在使用委托将几个值从A传递给B,这样我就可以在B VC中填充标签文本,一切都很好。然后我从B到C,这很好。但是当我从C回到B时,我有错误说委托值是零。 在进入C并返回B后,如何保持VC B中VC A的值? 对不起,如果它太混乱或者太简单了,我还是初学者。谢谢你的帮助。
修改
HomeViewController(A)
public string Page()
{
string page_ = "";
try
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
cmd.CommandText = "sp_master";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
["Name"], Sp_details = dt.Rows[i]["Sp_details"], Html_Links=dt.Rows[i]["Html_Links"] ,status = dt.Rows[i]["status"] });
page_ = page_ + "<li><a onclick='menu(" + dt.Rows[i]["Sp_details"] + ")'>" + dt.Rows[i]["ReportName"] + "</a></li>";
}
}
catch (Exception)
{
throw;
}
return page_;
}
RecipeDetailVC(B)
protocol recipeDetailVariables
{
var recipes:[String] { get set }
var recipeDescription: [String] { get set }
var indexPathRow: Int {get set}
}
protocol recipeDetailVCDelegate {
var delegate: recipeDetailVariables! { get set }
}
class HomeViewController ...
[...]
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "segueRecipeDetail") {
let destination = segue.destination as! RecipeDetailVC
destination.delegate = self
}
Ps:到目前为止一切都很好
RecipeReviewVC(C)
有一个segue via storyboard通过bar按钮带到这个VC,另一个segue返回RecipeDetailVC。当我返回RecipeDetailVC时,它在 class RecipeDetailVC[...]
override func viewDidLoad() {
super.viewDidLoad()
self.recipeTitle.text = delegate?.recipes[delegate.indexPathRow]
self.recipeInstructions.text = delegate?.recipeDescription[delegate.indexPathRow]
}
行失败,说它没有