好的.如果你有两个viewControllers,你从第一个到第二个进行模态Segue,那么你用[self dismissModalViewControllerAnimated:YES]解雇它; 它似乎没有回忆起viewDidLoad.我有一个主页面(viewController),然后是各种选项页面,我希望在更改选项时更新主页面.当我刚刚做了两个模态分段(一个前进,一个后退)时,这很有用,但这似乎是非结构化的,并且可能导致大型项目中的代码混乱.
我听说过push segues.他们还好吗?
谢谢.我感谢任何帮助:).
我试图将一个int从一个VC传递到另一个VC.我是这样做的.
在我的VC1中,showDetail当我调用prepareForSegue方法时,我正在做一个segue .看起来像这样.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = (NSIndexPath *)sender;
News *news = [arrNews objectAtIndex:indexPath.row];
NSLog(@"news id is %@",news.new_id);
if ([segue.identifier isEqualToString:@"showDetail"]) {
[segue.destinationViewController setNewsId:(int)news.new_id];
}
}
Run Code Online (Sandbox Code Playgroud)
在Log中我得到了正确的数字.现在在我的VC2中,我已经声明了这样的int.
@property (nonatomic) int newsId;
Run Code Online (Sandbox Code Playgroud)
我的setMethod看起来像这样.
-(void)setNewsId:(int)newsId{
NSLog(@"news id is %d",newsId);
self.newsId = newsId;
}
Run Code Online (Sandbox Code Playgroud)
当我执行时,我进入了一个包含所有大数字的循环.有人可以帮我解决这个问题吗?
我的xcode最近更新为6.0.1.在我的应用程序中,我实际上使用了一个popover segue用于测试目的.之后,xcode不断崩溃.我再次重新安装了xcode但没有结果.打开后再次崩溃.请给我解决方案来克服这个问题..

我有一个prepareForSegue在该方法设置发送我想要的一切的destinationViewController除了一个值UILabel上destinationVC.我扔了一个NSLog语句来查看它打印的值,它打印出我想要的内容.
它不会崩溃,但它没有设置.我知道我在这里遗漏了一些非常基本的东西,但它并没有向我跳出来.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton *)sender {
if ([[segue identifier] isEqualToString:@"directionsSegue"]) {
// Set destination view controller
DirectionsViewController *destinationVC = segue.destinationViewController;
// Pick out the "thing" you want to send to destinationVC
CGPoint point = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
// Set the "thing" on the destinationVC
PointOfInterest *poi = [self.fetchedResultsController objectAtIndexPath:indexPath];
destinationVC.destinationLabel.text = poi.name;
NSLog(@"destinationVC.destinationLabel.text = %@", poi.name);
destinationVC.destinationLatitude = poi.latitude;
destinationVC.destinationLongitude = poi.longitude;
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个注销按钮,我需要重置应用程序.看起来非常标准但我没有看到关于如何做这样的事情的很多信息.到目前为止,我已经设法删除了代表当前用户的NSUserDefaults对象,我使用FBSDKLoginManager().logOut()的是用户通过Facebook登录,然后我将根视图控制器重置为其初始视图控制器:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootViewController = HomeViewController()
appDelegate.window!.rootViewController = rootViewController
appDelegate.window!.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)
但是,我不确定是否还有其他事可做.我看到一个答案说你需要遍历所有windows子视图并删除它们,但是当你更改rootViewController时这仍然是必要的吗?还有什么我想念的吗?此外,截至目前,当您单击注销时,主屏幕才会出现.有没有办法让根视图控制器更改动画?
目前我有一个UITableViewCell和我在show那里附加了一个类型的segue - 当用户点击单元格时,会调用此方法:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "fullEventSegue"){
fullEventDetails = segue.destinationViewController as? FullEvent
}
}
Run Code Online (Sandbox Code Playgroud)
然后用户从此单元格重定向到FullEvent类(和视图).但现在我想检查是否是A类型的用户,如果是,则照常重定向,但如果没有 - 然后将其重定向到PartialEvent,例如:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (user == "typeA")
{
if (segue.identifier == "fullEventSegue"){
fullEventDetails = segue.destinationViewController as? FullEvent
}
}else{
if (segue.identifier == "partialEventSegue"){
partialEventDetails = segue.destinationViewController as? PartialEvent
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试连接两个segues storyboard但是当我连接第二个时 - 第一个消失了,对我而言,我看起来只能附加一个segue.有没有办法修复它并同时使用它们?
我正在尝试将数据传递UITableview给另一个UITableview,当我按下时我成功传递数据cell但是当我按下导航栏的后退按钮时我无法传回数据; 我已经尝试过全局变量来解决这个问题,但由于我将这些变量的日期存储在数据库中,这给我带来了很多问题,因为它强制执行所有存储的提醒以保存相同的数据,我可以做一些技巧解决这个问题,但我们都知道全局变量是不好的做法而且OOP都不确认MVC,问题是如何使用Prepare for segue函数传回数据; 请注意,表视图是静态的而不是动态的.
如果你问的是我试图传递的数据是星期几,例如选择星期五和星期六时它会将真值发送回前一个视图,如果取消选择星期五和星期六,则会将错误值发送回上一个视图
那我怎么解决这个问题呢?
提前致谢
当用户在iMessage应用程序中单击箭头以切换到扩展视图时,我具有下面的代码来处理大小调整,但是当用户在iMessage应用程序中选择到新的视图控制器时,如何以编程方式打开扩展视图?
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
// Called after the extension transitions to a new presentation style.
if presentationStyle == MSMessagesAppPresentationStyle.compact {
//Resize Views
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的segue方法。假设此方法位于ParentViewController中。
override fu n c prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "subViewController" {
// Before appears in the screen.
let subViewController = segue.destination as! SubViewController
subViewController.currentMarks = sender as? Int16
}
Run Code Online (Sandbox Code Playgroud)
它工作完美。现在进入SubViewController。在这里,我正在做某事,并且在这里有一个按钮。每当我单击此按钮时,它都应该关闭SubViewController并需要打开ParentViewController(因为它已经处于打开状态,所以无法打开)。
确切地说,每当我单击SubViewController中的按钮时,subViewController只需关闭然后我就会自动看到ParentViewController(因为已经打开了一个,但我没有关闭对吗?)。
如何实现这种机制?在SubViewController按钮操作中,我这样写:
self.navigationController?.dismiss(animated: true, completion: {
})
Run Code Online (Sandbox Code Playgroud)
但这没用。有人可以帮我吗?
我正在使用swift 4并有一个应用程序,人们可以通过我的应用程序打开他们的手机相机.我有一个ViewController被调用CameraController,它具有默认值UIView,我在其上面有一个视图,CameraView它显示用户摄像头和其他按钮.
当我点击其中一个按钮时,它会通过segue(PlacesController)将我带到另一个视图控制器.当我解雇时,PlacesController我回到CameraController现在,子视图现在需要大约8或10秒再次显示.
在某些情况下我可以在保持当前子视图的同时转到另一个控制器吗?
问题是,当我进入我的segue控制器PlaceController然后回到我的状态CameraController时,相机和子层变得可见之前需要大约8或10秒.特别是这个代码下面我想知道我是否可以保持我的子层仍然运行,因为它等待10秒显示太多了.
self.CameraView.layer.insertSublayer(previewLayer!, at: 0)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
class CameraController: UIViewController {
@IBOutlet weak var CameraView: UIView!
var previewLayer: AVCaptureVideoPreviewLayer?
let captureSession = AVCaptureSession()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
DispatchQueue.main.async {
self.beginSession()
}
func beginSession() {
// gets the camera showing and displays buttons on top of it
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.CameraView.layer.insertSublayer(previewLayer!, at: …Run Code Online (Sandbox Code Playgroud) segue ×10
ios ×9
swift ×5
objective-c ×3
storyboard ×2
xcode ×2
camera ×1
dismiss ×1
identifier ×1
imessage ×1
iphone ×1
logout ×1
swift3 ×1
uilabel ×1
uistoryboard ×1
uitableview ×1
view ×1
viewdidload ×1
xcode6 ×1