今、前の画面に表示されているTableViewCellのタイトルを画面遷移させたいと思っています。
これらの、TableViewCellにある「テスト」と「あ」を別の検索画面の方に画面遷移をさせたいのですが、うまくいきません。
Swift
1class CalendarViewController: UIViewController { 2 3 var DiaryArray: [Diary] = [] 4 5 @IBOutlet weak var Calendarview: FSCalendar! //関連付けしてあげます 6 @IBOutlet weak var DiaryTableView: UITableView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view. 11 Calendarview.dataSource = self //初期化していきます 12 Calendarview.delegate = self //初期化していきます 13 14 DiaryArray = Diary.search(date: Date()) 15 configureTableView() 16 } 17 func configureTableView() { 18 //dataSourceとdelegateメソッドが使えるようにしました 19 DiaryTableView.delegate = self //初期化していきます 20 DiaryTableView.dataSource = self //初期化していきます 21 DiaryTableView.tableFooterView = UIView() //余白を消す 22 } 23 24 override func viewWillAppear(_ animated: Bool) { 25 DiaryArray = Diary.search(date: Date()) 26 DiaryTableView.reloadData() 27 } 28 29override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 30 if segue.identifier == "toSearching" { 31 let dailysearchViewController = segue.destination as! SearchViewController 32 let selectedIndex = DiaryTableView.indexPathForSelectedRow! 33 dailysearchViewController.SearchDay = [DiaryArray[selectedIndex.row]] 34 } 35 } 36extension CalendarViewController: UITableViewDelegate, UITableViewDataSource { 37 38 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 39 return DiaryArray.count 40 } 41 42 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 43 let cell = tableView.dequeueReusableCell(withIdentifier: "DiaryCell")! 44 cell.textLabel?.text = DiaryArray[indexPath.row].title 45 return cell 46 } 47 48 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 49 self.performSegue(withIdentifier: "toDetails", sender: nil) // 詳細画面に遷移します 50 } 51 52} 53 54extension CalendarViewController: FSCalendarDataSource, FSCalendarDelegate,FSCalendarDelegateAppearance { 55 // MARK: - FSCalendar Delegate 56 func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { 57 //日付選択時に呼ばれるメソッド 58 DiaryArray = Diary.search(date: date) 59 DiaryTableView.reloadData() 60 61 } 62 63 64}
ここらが検索画面のViewControllerです。
Swift
1class SearchViewController: UIViewController, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource{ 2var SearchDay: [Diary] = [] 3override func viewDidLoad() { 4 super.viewDidLoad() 5 // Do any additional setup after loading the view. 6 print(SearchDay) //何にも配列に入ってこない 7 MyItems = SearchDay as NSArray //配列を挿入 8 SearchResult = MyItems //結果を挿入 9 10 }
初歩的な質問だと思いますが、ご教授願います。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/09/01 11:00