2017-05-11 20 views
-4

나는 앱에서 일하고 있으며 오른쪽으로 스 와이프하고 삭제를 클릭하여 행을 삭제하는 삭제 옵션을 만들고 싶습니다. "Expected Declaration"오류가 발생하고 약 20 분 동안 수정하려고했습니다.예상 선언 오류 예상 됨 TableView

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]; 


    } 
} 
+0

코드가 엉망입니다. Swift와 혼합 된 ObjC 함수 (닫기 대괄호 누락) 및 다른 함수 내부의 함수 AND 클래스가 있습니다. 또한 오류가 발생한 행을 알려주지 않으므로 컴파일러가 아닙니다. – EmilioPelaez

+0

미안 에러가 다음 행되어 약 –

+0

- (공극)를 tableView (jQuery과 *)를 tableView committEditStyle (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath (NSIndexPath *) indexPath {경우 (editingStyle == UITableViewCellEditingStyleDelete) { [maTheData removeObjectAtIndex : [indexPath 행]]; –

답변

1

메서드를 호출하는 대신 메서드를 호출합니다. 즉, func 안에 func입니다. 심지어 을 func 안에 넣을 수있는 방법을 모르겠습니까? Sandeep이 언급 한대로 Objective CSwift으로 섞어서 말합니다.

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) 
      } 
     } 
    } 
1

당신은 당신의 클래스의 나머지는 스위프트에있는 동안, 목표 C처럼 보이는

- (void)tableView:(UITableView *)tableView committEditStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath: (NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) { 
[maTheData removeObjectAtIndex: [indexPath row]]; 
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

혼합된다. 여러 언어를 사용하는 경우 혼합하기 쉽지만 컴파일러는 이와 같은 경우에 도움이됩니다.