我想使用didSelectRowAt从UITableView显示数组到下一个viewController

时间:2018-08-31 04:52:18

标签: ios arrays swift uitableview

我希望export class AppClass { flag: boolean = false; forwardOption: boolean; mesasgeList = []; sendMessage(msg: any) { this.flag = true; this.forwardOption = true; this.mesasgeList.push(msg); } get flagVar() { return this.flag } } 根据选择的单元格返回quizNumber

例如,如果用户选择了第一个单元格,则quizNumberArray返回1

在UITableViewController内部

quizNumber

在下一个ViewController中

let quizNumberArray = [1,2,3,4,5,6,7,8,9,10]
    var quizNum = Int()

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "toQuestionVC") as? QuestionVC
    quizNum = quizNumberArray[indexPath.row]
}
    override  func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let identifier = segue.identifier {
        if identifier == "toQuestionVC" {
            let questionController = segue.destination as! QuestionVC
            questionController.quizNumber = quizNum
}

但是class QuestionVC : UIViewController { var quizNumber = Int() func updateQuestion(){ if quizNumber == 1 { //..... } } } 返回0。

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

final WallpaperManager wallpaperManager = (WallpaperManager)getSystemService(
            Context.WALLPAPER_SERVICE);

Bitmap myBitmap = Bitmap.createScaledBitmap(
    Const.cropped_bitmap,
    wallpaperManager.getDesiredMinimumWidth(),
    wallpaperManager.getDesiredMinimumHeight(), 
    true);

wallpaperManager.suggestDesiredDimensions(
    wallpaperManager.getDesiredMinimumWidth(),
    wallpaperManager.getDesiredMinimumHeight());

try {
    wallpaperManager.setBitmap(myBitmap);
    Toast.makeText(CropImageActivity.this,
        CropImageActivity.this.getString(R.string.wallpaper_has_been_set), 0).show();
}
catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(CropImageActivity.this, "Wallpaper not set", 0).show();
}

并删除segue以使用上述代码