我在尝试将数据传递给其他一些视图控制器时遇到问题。我可以成功地执行segue,但我需要的补充数据并没有通过segue。
public class SpinnerCustomizationActivity extends Activity {
String[] spinnerValues = { "Blur", "NFS", "Burnout","GTA IV", "Racing", };
String[] spinnerSubs = { "Ultimate Game", "Need for Speed", "Ulimate Racing", "Rockstar Games", "Thunder Bolt" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner mySpinner = (Spinner) findViewById(R.id.spinner_show);
mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues)); }
public class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context ctx, int txtViewResourceId, String[] objects)
{
super(ctx, txtViewResourceId, objects); }
@Override
public View getDropDownView(int position, View cnvtView, ViewGroup prnt) { return getCustomView(position, cnvtView, prnt); }
@Override
public View getView(int pos, View cnvtView, ViewGroup prnt)
{
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View mySpinner = inflater.inflate(R.layout.custom_spinner, parent, false);
TextView main_text = (TextView)mySpinner.findViewById(R.id.text_main_seen);
main_text.setText(spinnerValues[position]);
TextView subSpinner = (TextView)mySpinner.findViewById(R.id.sub_text_seen);
subSpinner.setText(spinnerSubs[position]);
return mySpinner; }
}
}
如果有人能够确定为什么会这样,那就太棒了。谢谢!
答案 0 :(得分:3)
您未与
进行比较segue.identifier
in
if segue == "showTrailer1"{
和
else if segue == "addMovie"{
在.identifier
之后添加segue
将解决您的问题。
答案 1 :(得分:0)
在prepareForSegue
中,您必须使用segue.identifier
来检查哪个segue已被调用
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if segue.identifier == "showTrailer1"{
// Obtain the object reference of the destination view controller
let trailerViewController: MovieTrailerViewController = segue.destinationViewController as! MovieTrailerViewController
//Pass the data object to the destination view controller object
trailerViewController.youTubeMovieTrailerID = youtubeID
trailerViewController.movieTitle = movieTitle
}
else if segue.identifier == "addMovie"{
let addMovieViewController: AddMovieViewController = segue.destinationViewController as! AddMovieViewController
addMovieViewController.delegate = self
}
}