0
我很新的Swift编码。我有Android的经验。所以我知道我该怎么做Andorid。它如下所示;自定义TableView发送参数inSwift
public class MyUserProfileFragment extends BaseFragment {
MyUserProfileAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new MyUserProfileAdapter(MyUserProfileFragment.this, getActivity());
}
public showDialog(){
//do something
}
}
public class MyUserProfileAdapter extends BaseAdapter {
MyUserProfileFragment fragmentMyUserProfile;
Context context;
public MyUserProfileAdapter(MyUserProfileFragment fragment, Context context) {
this.context = context;
LayoutInflater layoutInflater = LayoutInflater.from(context);
this.fragmentMyUserProfile = fragment;
}
fragmentMyUserProfile.showDialog();
}
所以我可以使用MyUserProfileAdapter的MyUserProfileFragment中的所有方法。 但我不能在Swift中做到这一点。在斯威夫特我有;
class ViewControllerNewGame: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:MyCustomCell = self.tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as! MyCustomCell
return cell
}
func showDialog(){
//some actions
}
}
class MyCustomCell: UITableViewCell {
@IBOutlet weak var img1: UIButton!
@IBAction func click(sender: UIButton) {
//I want to use showDialog method from ViewVoncontroller
}
}
这些都是我的项目中非常类似的代码。我如何在Swift中使用showDialog方法?
哦,非常感谢你,我现在很开心:) – Aybuke
您的欢迎! :) –