我有一个有两个segues的应用程序.在其中一个segue中,当前视图控制器成为委托而另一个不成为委托.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"MoreOptions"]) {
UINavigationController *navigationController = segue.destinationViewController;
MoreOptionsViewController *controller = (MoreOptionsViewController *)navigationController.topViewController;
controller.delegate = self;
} else if ([segue.identifier isEqualToString:@"FullStoryView"]) {
SingleStoryViewController *detailViewController = segue.destinationViewController;
detailViewController.urlObject = sender;
}
}
Run Code Online (Sandbox Code Playgroud)
所有这一切都很好,但我想尝试更好地理解代码.我不明白的是,我必须通过从navigationController.topViewController中获取它来获取对MoreOptionsViewController的引用,而不是简单地从segue.destinationViewController获取它,就像我在第二个if条件中那样.是因为我将当前视图控制器(self)设置为委托吗?同样,我不是试图解决问题,而是试图更好地了解正在发生的事情.
在我们UIViewController一个接一个的三个s的iOS应用程序中,我们想根据某些条件跳过中间的一个,直接从第一个到第三个.但是,用户应该能够通过第三个控制器上的"后退"按钮返回第二个.
我试图[self performSegueWithIdentifier:@"segueId" sender:sender];从viewDidLoad,viewWillAppear但这破坏了导航栏,由调试日志指示.调用此代码viewDidAppear工作正常,但第二个视图已经显示,这是我首先想要避免的.
我也试过[self.navigationController pushViewController:vc animated:NO];但结果是同样损坏的导航栏,即使这次调试日志没有这样的条目.
这样做的支持方式是什么(如果可能的话)?
目标是带有iOS 5.1的iPhone4,开发环境是Xcode 4.3.
我不知道为什么dismissViewControllerAnimated:completion:.我只是想这样做.
我从一开始
[self performSegueWithIdentifier:@"my_segue" sender:self];
Run Code Online (Sandbox Code Playgroud)
但是,我打电话给解雇而不是没有任何反应.我可以创建另一个segue,但它会创建一个新的视图控制器.
我的问题是:如何解雇performSegueWithIdentifier:sender:?
我有一个表视图,其中包含不同类型的表视图单元格.在其中一个单元格中,有两个按钮,按下时加载视图控制器.我使用以下功能来处理按钮按下:
- (IBAction)leftButtonPressed:(id)sender
{
// Getting the pressed button
UIButton *button = (UIButton*)sender;
// Getting the indexpath
NSIndexPath *indPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
// Loading the proper data from my datasource
NSArray *clickedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indPath.row];
[[SOEventManager sharedEventManager] setSelectedEvent:clickedEvent[0]];
// Everything working as it should up to this point
// Performing seque...
[self performSegueWithIdentifier:@"buttonSegue" sender:self];
}
Run Code Online (Sandbox Code Playgroud)
我的buttonSegue应该推送一个新的视图控制器.不管怎样,而不是推动一次,它似乎是推了两次,所以我得到以下警告:
2013-11-27 01:48:30.894 Self-Ordering App[2081:70b] nested push animation can result in corrupted navigation bar
2013-11-27 01:48:31.570 Self-Ordering App[2081:70b] Finishing up a navigation …Run Code Online (Sandbox Code Playgroud) 我想将数据(例如set var)从modal segue传递给parent,我该怎么做?
我正在使用该代码退出模态segue:
@IBAction func doneClicked(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我不能segue.destinationViewController在这里使用传递数据,就像我以前在push segues上做的那样.
如何使用Swift将存储在标签中的数据从我的接口控制器传递到WatchKit中的另一个接口控制器?我似乎无法在任何地方找到答案,希望有人在这里可以帮助我.我已经包含了我的代码部分,它涉及计算我需要传递的值.我基本上想要显示用户计算的相同值,并在下一个名为ResultsController的接口控制器中详细说明.非常感谢任何帮助:D
class InterfaceController: WKInterfaceController {
var currentValue: String = "0"
func setDisplayValue(value: Double)
{
var percent = value
// check if value is an integer
if value % 1 == 0
{
// our value is an integer
currentValue = "\(Int(value))"// new value %
}
else
{
// our value is a float
currentValue = "\(value)"
}
// Display 2 decimal places in final amount
var round = NSString(format:"%.2f", value)
displayLabel.setText("$\(round)") // Display final value
// This value is what …Run Code Online (Sandbox Code Playgroud) 在iOS 8.4,模拟器和手机中,我的performSegue调用没有遇到任何问题,但是当在Xcode 7 beta 5上使用模拟器时,当执行performSegue调用时,它会崩溃.调用堆栈如下.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 3 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001137509b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001131c8deb objc_exception_throw + 48
2 CoreFoundation 0x00000001136179d5 -[__NSArrayM insertObject:atIndex:] + 901
3 Foundation 0x0000000110c42aa1 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 106
4 CoreFoundation 0x000000011366beb2 -[NSMutableArray insertObjects:count:atIndex:] + 162
5 CoreFoundation 0x000000011366bc1f -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 335
6 CoreFoundation 0x000000011366baa3 -[NSMutableArray addObjectsFromArray:] + 723
7 UIKit 0x00000001119ef467 …Run Code Online (Sandbox Code Playgroud) 我正在使用a UISplitViewController,a MasterViewController和s DetailViewController,没有UINavigationControllers.
Currenly为主 - >细节的segue动画,由
performSegueWithIdentifier("showDetail", sender: self)
Run Code Online (Sandbox Code Playgroud)
包括DetailViewController从下往上显示.
如何让动画显示左侧病房?
uinavigationcontroller uisplitviewcontroller ios segue swift
我正在尝试在iOS 10和Swift 3中测试unwind segue.
我在TableViewController类中添加了segue的代码,并在表视图控制器场景中连接"取消"按钮和退出:
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) {
print("Unwind to Root View Controller")
}
Run Code Online (Sandbox Code Playgroud)
但我的简单segue不起作用.我究竟做错了什么?
我试图在第一次加载应用程序时执行segue.我可以在调试器中看到我的打印消息,但Perform Segue不起作用.我没有得到任何错误.有人可以告诉我什么错了吗?
import UIKit
import LocalAuthentication
let isFirstLaunch = UserDefaults.isFirstLaunch()
extension UserDefaults {
// check for is first launch - only true on first invocation after app install, false on all further invocations
// Note: Store this value in AppDelegate if you have multiple places where you are checking for this flag
static func isFirstLaunch() -> Bool {
let hasBeenLaunchedBeforeFlag = "hasBeenLaunchedBeforeFlag"
let isFirstLaunch = !UserDefaults.standard.bool(forKey: hasBeenLaunchedBeforeFlag)
if (isFirstLaunch) {
UserDefaults.standard.set(true, forKey: hasBeenLaunchedBeforeFlag)
UserDefaults.standard.synchronize()
}
return isFirstLaunch
}
}
class …Run Code Online (Sandbox Code Playgroud) segue ×10
ios ×9
swift ×5
iphone ×3
objective-c ×2
cocoa-touch ×1
delegates ×1
ios7 ×1
ios9 ×1
storyboard ×1
swift3 ×1
unwind-segue ×1
viewdidload ×1
watchkit ×1
xcode ×1
xcode7-beta5 ×1