【发布时间】:2017-05-11 20:34:55
【问题描述】:
我正在开发一个应用程序,并且想要创建一个删除选项,您可以在其中向右滑动并单击删除以删除一行。我收到“预期声明”错误,我已尝试修复它大约 20 分钟。
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];
}
}
【问题讨论】:
-
你的代码全乱了。你有一个 ObjC 函数(缺少右括号)与 Swift 和一个函数以及另一个函数中的一个类混合。你也忘了告诉我们错误在哪一行,我们不是编译器。
-
对不起,错误在这些行中
-
- (void)tableView:(UITableView *)tableView committEditStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath: (NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) { [maTheData removeObjectAtIndex: [indexPath row]] ;
标签: ios swift uitableview tableview tablecell