gpt4 book ai didi

ios - Swift xcode 错误 : load controller is not allowed and autoresize not equal to views window

转载 作者:行者123 更新时间:2023-11-30 13:37:10 25 4
gpt4 key购买 nike

我正在尝试创建的内容的屏幕截图:screen layout

注意:如果您决定运行该项目,则无需查看下面的代码,因为我在下面发布的所有类都位于 dropbox 压缩项目文件内。

底部的每个方 block 都选择不同的颜色,并且有一个不可见的方 block 选择绿色方 block 右侧的形状类型。用户选择其中一种形状后,用户将能够在屏幕的特定部分进行绘制。

整个项目:https://www.dropbox.com/s/f9pr0wo0j74iw4a/XcodeSwiftProject99999.zip?dl=0

如果您运行该项目,创建一个帐户,然后单击登录,然后单击其中一行,然后单击彩色框之一(红色和绿色方 block ),应用程序将崩溃并收到以下错误消息:

2016-03-11 17:06:43.580 finalProject2[11487:1058358] <UIView: 0x7faba1677710; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x7faba1658d90>; layer = <CALayer: 0x7faba16563f0>>'s window is not equal to <finalProject2.RowTableViewController: 0x7faba165a3c0>'s view's window!

File slot 1

File slot 2

File slot 3

File slot 4

File slot 5

File slot 6

File slot 7

File slot 8

File slot 9

File slot 10

File slot 11

File slot 12

2016-03-11 17:06:44.746 finalProject2[11487:1058358] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7faba16b7d60>)

MainProject场景类:

import UIKit



weak var FirstFileNameTextField: UILabel!

enum ShapeType: String

{

case Line = "Line"

case Ellipse = "Ellipse"

case Rectangle = "Rectangle"

case FilledEllipse = "Filled Ellipse"

case FilledRectangle = "Filled Rectangle"

case Scribble = "Scribble"

}

let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ]



class MainProjectScene: UIViewController

{

var row: Row?







@IBAction func PressedSaveAs(sender: UIButton) //this is the save as function that I would like to know how to change



{



//1. Create the alert controller.



var alert = UIAlertController(title: "Name/rename your file:", message: "Enter a filename to name/rename and save your file", preferredStyle: .Alert)



//2. Add the text field. You can configure it however you need.



alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in



textField.text = "Your file name"

})



alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:

{

(action) -> Void in

let textField = alert.textFields![0] as UITextField

print("Text field: \(textField.text)")

// rows.cell.textLabel?.text = textField.text

CurrentFileName = textField.text!

rows[IndexPath.row].FileName = textField.text!

rows[IndexPath.row].UserText = self.TextUserScrollEdit.text!



}))



// 4. Present the alert.

self.presentViewController(alert, animated: true, completion: nil)





// rows[indexPath.row].FileName = rows.cell.textLabel?.text



// rows[i] = textField.text



// if let detailViewController = segue.destinationViewController as? MainProjectScene {



// if let cell = sender as? UITableViewCell {



// if let indexPath = self.tableView.indexPathForCell(cell) {



// detailViewController.row = rows[indexPath.row]



}





override func viewWillAppear(animated: Bool)

{



if let r = row

{



row!.FileName = r.FileName



row!.QuartzImage = r.QuartzImage



row!.UserText = r.UserText

rows[IndexPath.row].UserText = self.TextUserScrollEdit.text! }

}





override func viewDidLoad()

{

super.viewDidLoad()

TextUserScrollEdit.text = rows[IndexPath.row].UserText

// FacebookButton.addTarget(self, action: "didTapFacebook", forControlEvents: .TouchUpInside)



}



@IBOutlet weak var TextUserScrollEdit: UITextView!

@IBOutlet weak var NewFileButton: UIButton!

@IBOutlet weak var TwoDQuartzButton: UIButton!

@IBOutlet weak var YouTubeButton: UIButton!

@IBOutlet weak var TwitterButton: UIButton!

@IBOutlet weak var OpenFileButton: UIButton!

@IBOutlet weak var SnapChatButton: UIButton!

@IBOutlet weak var FacebookButton: UIButton!

@IBAction func PressedTwoDQuartzButton(sender: UIButton) {



}



@IBAction func PressedSnapchatButton(sender: UIButton){



UIApplication.sharedApplication().openURL(NSURL(string: "https://www.snapchat.com/")!)



}



@IBAction func PressedYouTubeButton(sender: UIButton) {



UIApplication.sharedApplication().openURL(NSURL(string: "https://www.youtube.com/")!)



}



@IBOutlet weak var InstagramButton: UIButton!

@IBAction func PressedFacebookButton(sender: UIButton) {



UIApplication.sharedApplication().openURL(NSURL(string: "http://www.facebook.com")!)



}

@IBAction func PressedInstagramButton(sender: UIButton) {



UIApplication.sharedApplication().openURL(NSURL(string: "https://www.instagram.com/")!)



}



@IBAction func PressedTwitterButton(sender: UIButton) {



UIApplication.sharedApplication().openURL(NSURL(string: "https://twitter.com/")!)



}



@IBOutlet weak var SaveAsButton: UIButton!













// @IBOutlet weak var shapeButton: ShapeButton!



@IBOutlet weak var canvas: CanvasView!



@IBOutlet var colorButtons: [UIButton]!



@IBOutlet weak var shapeButton: ShapeButton!



@IBAction func selectColor(sender: UIButton) {

UIView.animateWithDuration(0.5, delay: 0.0,

usingSpringWithDamping: CGFloat(0.25),

initialSpringVelocity: CGFloat(0.25),

options: UIViewAnimationOptions.CurveEaseInOut, animations: {

for button in self.colorButtons {

button.frame.origin.y = self.view.bounds.height - 58

}

sender.frame.origin.y -= 20

}, completion: nil)

canvas.color = sender.backgroundColor!

shapeButton.color = sender.backgroundColor!

}



@IBAction func selectShape(sender: ShapeButton) {

let title = "Select Shape"

let alertController = UIAlertController(title: title, message: nil, preferredStyle: .ActionSheet)



for shape in shapes {

let action = UIAlertAction(title: shape.rawValue, style: .Default) { action in

sender.shape = shape

self.canvas.shape = shape

}

alertController.addAction(action)

}

presentViewController(alertController, animated: true, completion: nil)

}



}

ShapeButton 类:

import UIKit





class ShapeButton: UIButton {





let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ]



var shape: ShapeType = .Line {

didSet {

setNeedsDisplay()

}

}



var color: UIColor = UIColor.blueColor() {

didSet {

setNeedsDisplay()

}

}



// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

override func drawRect(rect: CGRect) {

// Drawing code

let context = UIGraphicsGetCurrentContext()

CGContextSetStrokeColorWithColor(context, color.CGColor)

CGContextSetFillColorWithColor(context, color.CGColor)

CGContextSetLineWidth(context, 2)



let x1: CGFloat = 5

let y1: CGFloat = 5

let x2: CGFloat = frame.width - 5

let y2: CGFloat = frame.height - 5

let rect = CGRect(x: x1, y: y1 + 5, width: frame.width - 10, height: frame.height - 20)

switch shape {

case .Line:

CGContextMoveToPoint(context, x1, y1)

CGContextAddLineToPoint(context, x2, y2)

CGContextStrokePath(context)

case .Ellipse:

CGContextStrokeEllipseInRect(context, rect)

case .Rectangle:

CGContextStrokeRect(context, rect)

case .FilledEllipse:

CGContextFillEllipseInRect(context, rect)

case .FilledRectangle:

CGContextFillRect(context, rect)

case .Scribble:

CGContextMoveToPoint(context, x1, y1)

CGContextAddCurveToPoint(context,

x1 + 80, y1 - 10, // the 1st control point

x2 - 80, y2 + 10, // the 2nd control point

x2, y2) // the end point

CGContextStrokePath(context)

}

}





}

Canvas View 类:

import UIKit



/*

This program is for Xcode 6.3 and Swift 1.2

*/





class CanvasView: UIView {





var shape: ShapeType = .Line

var color: UIColor = UIColor.blueColor()

var first :CGPoint = CGPointZero

var last :CGPoint = CGPointZero

var points: [CGPoint] = []



// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

override func drawRect(rect: CGRect) {

// Drawing code

let context = UIGraphicsGetCurrentContext()

CGContextSetStrokeColorWithColor(context, color.CGColor)

CGContextSetFillColorWithColor(context, color.CGColor)



let rect = CGRect(x: first.x, y: first.y, width: last.x - first.x, height: last.y - first.y)

switch shape {

case .Line:

CGContextMoveToPoint(context, first.x, first.y)

CGContextAddLineToPoint(context, last.x, last.y)

CGContextStrokePath(context)

case .Ellipse:

CGContextStrokeEllipseInRect(context, rect)

case .Rectangle:

CGContextStrokeRect(context, rect)

case .FilledEllipse:

CGContextFillEllipseInRect(context, rect)

case .FilledRectangle:

CGContextFillRect(context, rect)

case .Scribble:

CGContextMoveToPoint(context, first.x, first.y)

for p in points {

CGContextAddLineToPoint(context, p.x, p.y)

}

CGContextStrokePath(context)

}

}



override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

if let touch = touches.first {

first = touch.locationInView(self)

last = first

points.removeAll(keepCapacity: true)

if shape == .Scribble {

points.append(first)

}

setNeedsDisplay()

}

}



override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

if let touch = touches.first {

last = touch.locationInView(self)

if shape == .Scribble {

points.append(last)

}

setNeedsDisplay()

}

}



override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

if let touch = touches.first {

last = touch.locationInView(self)

if shape == .Scribble {

points.append(last)

}

setNeedsDisplay()

}

}



override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {

}




}

最佳答案

在 Storyboard中,转到 MainProjectScene 并右键单击 CanvasView

您将有两个 CanvasView 的引用导出。

删除两个引用 socket 。现在再次选择 CanvasView 并转到身份检查器并确保 View 的类是 CanvasView

保留主 Storyboard和 MainProjectScene 并将您的 CanvasView 链接到 Storyboard中的 View ,如下所示

这解决了问题。

我只是向您介绍一下您刚刚遇到的问题的一些见解。您可能首先在代码中创建了一个 View 导出并链接它,然后将其删除。那么您必须再次创建它并链接它。执行此操作后,您的 View 上将有 2 个引用点。您需要删除刚刚删除的那个,否则代码将崩溃。

关于ios - Swift xcode 错误 : load controller is not allowed and autoresize not equal to views window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35952516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com