0
私はSwiftコーディングで非常に新しいです。私はAndroidでの経験があります。だから私はこれをどうやってやることができるかは、アンドロイドです。それは以下のようなものです。カスタムTableViewパラメータを送信します。
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
あなたの歓迎、どうもありがとうございました! :) –