2014-10-20 16 views
5

Si verificano problemi nel tentativo di ottenere una sottoclasse di UITextField per il rendering correttamente in Interface Builder con IBDesignable. La sottoclasse è piuttosto semplice, consente all'utente di definire gli inserimenti per il posizionamento del testo in un UITextField. Il codice è il seguente:Errori con rendering sottoclasse UITextField personalizzato in Interface Builder

import Foundation 

@IBDesignable public class CLYInsetTextField: UITextField { 

    @IBInspectable public var topInset: CGFloat = 0 { 
     didSet { 
      self.setNeedsDisplay() 
     } 
    } 
    @IBInspectable public var leftInset: CGFloat = 0 { 
     didSet { 
      self.setNeedsDisplay() 
     } 
    } 
    @IBInspectable public var bottomInset: CGFloat = 0 { 
     didSet { 
      self.setNeedsDisplay() 
     } 
    } 
    @IBInspectable public var rightInset: CGFloat = 0 { 
     didSet { 
      self.setNeedsDisplay() 
     } 
    } 

    override public func textRectForBounds(bounds: CGRect) -> CGRect { 
     return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset)) 
    } 

    override public func editingRectForBounds(bounds: CGRect) -> CGRect { 
     return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset)) 
    } 
} 

Quando si utilizza questa classe in uno storyboard, le proprietà mostrano in IB perfettamente soddisfacente, ma quando provo ad aggiornare uno dei valori, Xcode costruisce il progetto e sputa il seguente due avvertimenti:

error: IB Designables: Failed to update auto layout status: dlopen([APP_NAME].app, 1): no suitable image found. Did find: 
[APP_NAME].app: can't map unslidable segment __TEXT to 0x100000000 with size 0x7EB000 

error: IB Designables: Failed to render instance of CLYInsetTextField: dlopen([APP_NAME].app, 1): no suitable image found. Did find: 
[APP_NAME].app: can't map unslidable segment __TEXT to 0x100000000 with size 0x7EB000 

posso costruire e gestire nel simulatore bene, e quando lo faccio la vista è resa come mi aspetto che. È solo quando cerco di renderlo in IB che mi viene in mente questo problema. Altri esempi che ho visto per creare viste personalizzate interattive in Interface Builder sembrano essere semplici come le mie e funzionare senza problemi. C'è un passo che mi manca, o è quello che sto cercando di fare semplicemente non andando a lavorare?

risposta

Problemi correlati