2017-05-08 106 views
-1

我最近修復了一些在此代碼中出現的錯誤,但是出現了一個新錯誤,而我和我的老師都無法修復它。它說「預期申報」 我該如何解決這個問題?在表格視圖中刪除行

import UIKit 

    class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

     var StoredValues = Values() 
     override func viewDidLoad() { 
      super.viewDidLoad() 
     } 
     override func didReceiveMemoryWarning() { 
      super.didReceiveMemoryWarning() 
     } 

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
      return UITableViewCell() 
     } 

     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
      return 4 
     } 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
      self.performSegue(withIdentifier: "meunSegue", sender: self) 

      func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
       _ = segue.destination as! SecondViewController 
      } 
      class SecondViewController: UIViewController { 

       var recievedData = "" 
       override func viewDidLoad() { 
        super.viewDidLoad() 
        print(recievedData) 
       } 
      } 
     } 
     - (void)tableView:(UITableView *)tableView committEditStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath: (NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [maTheData removeObjectAtIndex: [indexPath row]]; 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 


     } 
    } 
+1

尋找另一位至少具備基礎知識的老師。您正在嵌套委託方法甚至類聲明。 – vadian

回答

1

您試圖在同一個文件中混合使用Object-C和Swift。下面是您的代碼的Swift 3版本。

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
    if editingStyle == .delete { 
     maTheData.remove(at: indexPath.row) 
     tableView.deleteRows(at: [indexPath], with: .fade) 
    } 
} 
+0

@vadian它會編譯,如果你添加'var maTheData:[NSManagedObject] = []'這只是爲了向他們展示Swift文件中作爲Objective-C代碼的Swift版本。 – MwcsMac

+0

@vadian它會爲我編譯它不會顯示刪除功能的方式,但你是正確的,它應該是提交。 – MwcsMac