所以我有一个 VC,当单击按钮时我会调用它(它是一个 MFMailComposeViewController),并且当发送消息时,它会关闭 ViewController,我希望它在发送完成后呈现一个不同的视图控制器。但每次发送电子邮件后它都会崩溃,而不是这样做。我知道我做错了什么,但我不确定是什么。
这是我的代码,它消除并呈现新的代码。
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:true completion:nil];
[self presentViewController:_emailConfirmationPage animated:YES completion:nil];}
Run Code Online (Sandbox Code Playgroud)
我认为问题是我使用的self,但我不确定我用什么来代替它。
在我的应用程序中,有三个故事板。我想知道的是如何在视图控制器代码中获取故事板 ID/名称,因为 UIStoryBoard init func 采用第一个参数名称:String。它存储在哪里以及如何访问它?
我想从故事板中完全删除/删除我不使用的视图控制器。这是我不需要的额外视图控制器。有没有办法从故事板中完全删除/删除未使用的视图控制器?
我已经创建了一个简单的应用程序,它使用故事板来呈现一个新页面/类。但是,我想以编程方式做同样的事情。
我的初始 ViewController.swift 文件如下所示:
import UIKit
class ViewController: UIViewController {
var mainImageView: UIImageView!
var chooseButton: UIButton!
var nameLabel: UILabel!
override func loadView() {
view = UIView()
view.backgroundColor = .white
let chooseButton = UIButton(type: .custom) as UIButton
chooseButton.backgroundColor = .blue
chooseButton.layer.borderColor = UIColor.darkGray.cgColor
chooseButton.layer.borderWidth = 2
chooseButton.setTitle("Pick a side", for: .normal)
chooseButton.frame = CGRect(x: 100, y: 100, width: 200, height: 100)
chooseButton.addTarget(self, action: #selector(clickMe), for: .touchUpInside)
chooseButton.layer.cornerRadius = chooseButton.frame.size.height/2
self.view.addSubview(chooseButton)
self.nameLabel = UILabel()
nameLabel.text = "Here is your side"
nameLabel.textAlignment = …Run Code Online (Sandbox Code Playgroud) 我正在尝试更改标签的文本或在我的 iOS 应用程序从后台状态变为活动状态时显示警报。
当我调用 ViewController 类中的函数时,只有 print() 方法可以正常工作。但是当我想与该类中的对象交互时,它会显示错误。
SceneDelegate.swift:
var vc = ViewController()
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
vc.showMessage("Test message")
}
Run Code Online (Sandbox Code Playgroud)
ViewController.swift:
@IBOutlet weak var textLabel: UILabel!
func showMessage(_ incomingMessage:String!) {
let warning = UIAlertController(title: "Warning", message: incomingMessage, preferredStyle: .alert)
let aButton = UIAlertAction(title: "OK", …Run Code Online (Sandbox Code Playgroud) I have a table in which I need to add a title view. I made it in an xib file to configure as I need, but I have problems connecting this view. Tell me what I'm doing wrong!
class HeaderTableView: UITableViewHeaderFooterView {
//I think in this class a mistake
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "HeaderTableView", bundle: nil) …Run Code Online (Sandbox Code Playgroud) 我有一个UIVIewController"controller1".该控制器使用initWithNibName ...与"file1.xib"进行实例化.我想动态地将我的"controller1"的xib文件更改为"file2.xib"
恢复 :
"controller1"< - >"file1.xib",我想动态地拥有:"controler1"< - >"file2.xib"
我怎样才能做到这一点 ?
希望我很清楚.
我有一个iOS应用程序,我正在重写在Mac和iOS上工作.我的观点运作得相当好,但目前一切都是静态的.
我通常使用视图控制器代码做什么?在仅限iOS的应用程序中,通常会出现一些内容,例如"如果用户触摸此处,请执行此操作".
我找到了hitTest:方法.所以我很确定我可以编写所有内容以便它可以工作.我想我的问题更具组织性.理想情况下,我想要进行设置,以便当前在UIViewController子类中的代码可以在两个平台上运行.
我在XCode工作,我将视图控制器复制到另一个项目,但所有连接/出口仍然连接到旧项目.如果我将鼠标悬停在连接点上,它会突出显示另一个项目中的插座对象.如何删除课程的所有连接?
似乎ViewController的名称是相同的,如果我添加一个相同类型和名称的IBOutlet,它将自动连接到旧项目.
谢谢!
xcode objective-c interface-builder storyboard viewcontroller
我有一个视图控制器,我提出以下目标c代码:
CATransition *animation=[CATransition animation];
animation.delegate=self;
animation.duration=0.3;
animation.type=kCATransitionMoveIn;
animation.subtype=kCATransitionFromRight;
[self presentViewController:reader animated:NO completion:nil];
[reader.view.layer addAnimation:animation forKey:@"animation"];
Run Code Online (Sandbox Code Playgroud)
并在委托方法中使用类似的代码解雇
CATransition *animation=[CATransition animation];
animation.delegate=self;
animation.duration=0.3;
animation.type=kCATransitionMoveIn;
animation.subtype=kCATransitionFromLeft;
[self dismissViewControllerAnimated:NO completion:nil];
[self.view.layer addAnimation:animation forKey:@"animation"];
Run Code Online (Sandbox Code Playgroud)
但是有一个问题:与使用导航控制器不同,您可以看到一个视图滑动到其他视图上; 这里旧视图立即消失,因此新视图移动到空白视图.
我该如何解决这个问题?我需要这个代码在IOS 6,7和8中工作,并希望它看起来像在导航控制器内部的视图之间来回看时的水平动画.
编辑:我接受的解决方案有iOS 6的错误,如果我能找到修复它的解决方案,我将编辑这篇文章.
编辑2:找到它.看来,因为我提出了一个zBar视图控制器,我需要使用这段代码
zbarController.wantsFullScreenLayout=NO;
Run Code Online (Sandbox Code Playgroud)
在我设置cameraOverlayView之后.
viewcontroller ×10
ios ×5
swift ×4
iphone ×3
objective-c ×3
storyboard ×3
xcode ×2
ios13 ×1
ipad ×1
macos ×1
nib ×1
portability ×1
tableview ×1
view ×1
xcode8 ×1
xib ×1