我正在使用DialogFragments做很多事情:从列表中选择项目,输入文本.
将值(即字符串或列表中的项)返回给调用活动/片段的最佳方法是什么?
目前我正在制作调用活动实现DismissListener
,并为DialogFragment提供对活动的引用.然后,Dialog调用OnDimiss
activity中的方法,activity将从DialogFragment对象中获取结果.非常混乱,因为DialogFragment失去对活动的引用,它不能用于配置更改(方向更改).
谢谢你的帮助.
我正在使用a DialogFragment
,虽然我已成功设置图像以在关闭时关闭(即关闭)对话框,但当用户点击对话框外的任何地方时,我很难找到解除对话框的方法,就像它一样正常的对话.我以为会有某种
dialogFragment.setCanceledOnTouchOutside(true);
Run Code Online (Sandbox Code Playgroud)
打电话,但我没有在文档中看到.
这有可能DialogFragment
吗?或者我在错误的地方寻找?我尝试拦截"父母"活动中的触摸事件,但除了没有得到任何触摸事件外,它对我来说似乎不对.
某些应用程序的通知无法通过滑动来解除.
我该如何管理这种行为?
我有一个应用程序,它是一个单一的视图应用程序 我有一个导航控制器链接到根视图控制器中的所有子控制器.
在每个子控制器中,我都有一个注销按钮.我想知道我是否可以使用一个可以调用的功能,这将解除所有已经打开的控制器,无论当用户按下注销时哪个控制器当前打开?
我的基本开始:
func tryLogout(){
self.dismissViewControllerAnimated(true, completion: nil)
let navigationController = UINavigationController(rootViewController: UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("LoginViewController") )
self.presentViewController(navigationController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找执行此任务的最有效的内存方式.我将我的注销函数放在一个单独的utils文件中,但是我不能使用self.而且我仍然知道要动态解除哪些控制器的问题.
已建议更新 Pop到根视图控制器.所以我的尝试是这样的:
func tryLogout(ViewController : UIViewController){
print("do something")
dispatch_async(dispatch_get_main_queue(), {
ViewController.navigationController?.popToRootViewControllerAnimated(true)
return
})
}
Run Code Online (Sandbox Code Playgroud)
这是实现我追求目标的最佳途径吗?
我有一个很长的View Controllers层次结构;
在第一个View Controller中我使用此代码:
SecondViewController *svc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:svc animated:YES];
[svc release];
Run Code Online (Sandbox Code Playgroud)
在第二个View Controller中,我使用以下代码:
ThirdViewController *tvc = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self presentModalViewController:tvc animated:YES];
[tvc release];
Run Code Online (Sandbox Code Playgroud)
等等.
所以有一段时间我有很多View Controllers,我需要回到第一个View Controller.如果我一次回来一步,我会在每个View Controller中使用这段代码:
[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
如果我想直接从第六个View Controller返回到第一个,我必须做什么才能立即解除所有控制器?
谢谢
我创建了包含4个按钮的AlertDialog
OptionDialog = new AlertDialog.Builder(this);
OptionDialog.setTitle("Options");
LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.options, null, false);
background = (Button) v.findViewById(R.id.bkgSpinnerLabel);
SoundVib = (Button) v.findViewById(R.id.SoundVibSpinnerLabel);
OptionDialog.setView(v);
OptionDialog.setCancelable(true);
OptionDialog.setNeutralButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
background.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SetBackground();
// here I want to dismiss it after SetBackground() method
}
});
SoundVib.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent soundVibIntent = new Intent(SebhaActivity.this, EditPreferences.class);
startActivity(soundVibIntent);
}
});
OptionDialog.show();
Run Code Online (Sandbox Code Playgroud)
我想在SetBackground()方法之后解雇它,我该怎么做呢?提前致谢.
我正在使用SpriteKit制作游戏.我有3个viewControllers:选择level vc,game vc和win vc.游戏结束后,我想显示win vc,然后如果我按下win vc上的OK按钮,我想解雇win vc和游戏vc(从堆栈中弹出两个视图控制器).但我不知道怎么做,因为如果我打电话
self.dismissViewControllerAnimated(true, completion: {})
Run Code Online (Sandbox Code Playgroud)
win vc(堆栈顶部)被解雇,所以我不知道在哪里再次调用它来解雇游戏vc.有没有办法在不使用导航控制器的情况下解决这个问题?
这是第一个VC :(请注意以下以"//"开头的评论)
class SelectLevelViewController: UIViewController { // I implemented a UIButton on its storyboard, and its segue shows GameViewController
override func viewDidLoad() {
super.viewDidLoad()
}
}
Run Code Online (Sandbox Code Playgroud)
这是第二个VC:
class GameViewController: UIViewController, UIPopoverPresentationControllerDelegate {
var scene: GameScene!
var stage: Stage!
var startTime = NSTimeInterval()
var timer = NSTimer()
var seconds: Double = 0
var timeStopped = false
var score = 0
@IBOutlet weak var targetLabel: UILabel!
@IBOutlet var displayTimeLabel: UILabel! …
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,如何关闭警告框?我不想导致内存泄漏.我在alertDialog上尝试了.dismiss(),但是没有用......谢谢
// User pressed the stop button
public void StopMsg_button_action(View view){
final EditText password_input = new EditText(this); // create an text input field
password_input.setHint("Enter Password"); // put a hint in it
password_input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // change it to password type
AlertDialog.Builder alertDialog = new Builder(this); // create an alert box
alertDialog.setTitle("Enter Password"); // set the title
alertDialog.setView(password_input); // insert the password text field in the alert box
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, …
Run Code Online (Sandbox Code Playgroud) 如果对话框被解除,我想为我的背景做一些事情.所以我想知道对话框是否被解雇
所以有一个带有三个视图控制器的堆栈,其中A是根,B是第一个模态视图控制器,C是第三个模态vc.我想立刻从C到A.我已经尝试过这个解决方案来解雇.它确实有效但不是以正确的方式.也就是说,当最后一个视图控制器被解除时,它将在显示第一个视图控制器之前完全显示第二个视图控制器.我正在寻找的是一种从第三个vc到第一个vc的方法在一个不错的动画中没有注意到第二个视图.任何有关这方面的帮助都非常有用.