Post

Replies

Boosts

Views

Activity

Reply to programmatic constraints and Interface Builder
I wanted to simplify my problem, that's why I put the constraints in the subclass (class Container) It is exactly the same if I put the constraints in the code of the ViewController  I think the problem is that Interface Builder doesn't apply constraints. If I add the following method:  func setupIBConstraints() {     if (superview?.frame.size.width)! < (superview?.frame.size.height)! {       label.text = "setupIBConstraints(.CR \(superview?.frame.size.width)"       label.sizeToFit() self.layer.frame = CGRect(x: 30, y: 100, width: (superview?.frame.size.width ?? 0)-60, height: (superview?.frame.size.height ?? 0)-300)     } else {       label.text = "setupIBConstraints(.CC ou .RC \(superview?.frame.size.width)"       label.sizeToFit()       self.layer.frame = CGRect(x: 20, y: 50, width: (superview?.frame.size.width ?? 0)-100, height: (superview?.frame.size.height ?? 0)-100)     }   } and in method layoutSubviews() I replace setupConstraints(theOrientation) by  #if TARGET_INTERFACE_BUILDER      setupIBConstraints() #else     setupConstraints(theOrientation)  #endif  I can see a correct result in Interface Builder  it proves that code is well executed by Interface Builder change of frame is OK for IB but it doesn't apply constraints  I would reformulate my question: how to apply programmatic constraints in IB  Of course, I can write constraints in IB but I thought it was possible by program and see the results in IB
Aug ’21
Reply to Changing orientation in UITableViewCell
Yes of course I set variations of constraints But I don't see the result in Interface Builder. Imagine just a UItableViewCell. If I made variations, in portrait mode the width will be for instance 400, and in Landscape Mode the width will be 800. But there is no visual in IB. If I go in portrait mode, or in landscape mode, the visual doesn't change, even if I put the width in constraint
Dec ’20
Reply to currentEditor
All is my faultThe lesson of it is we have to think much more harder before making a postMy subclassed control, in the override function becomeFirstResponder didn't called super.becomeFirstResponder (the function of the NSTextField). As a result, currentEditor() of the control returned nil.When calling super.becomeFirstResponder, the function currentEditor returns the desired editor.Sorry about all this
Apr ’20
Reply to currentEditor
after the preceding answer, I saw that you added questionsAre you sure it is the textField (ctrlRch) ?After the window?.makefirstRespnder(ctrlRch), if i write Swift.print("firstResponder is \(window?.firstResponder)") I have the following in the debugging console: firstResponder is Optional(&lt;ivrit2.cTextField: 0x1020172f0&gt;)If I understand well, fieldEditor is a NSText. Could you check the type ?No, I can't check the type of fieldEditor, because the currentEditor() function of ctrlRch always return nilYou use selectedRange on NSText. Why not set selectedRange on the textField ?If I write ctrlRch.selectedRange I hve the following error: Value of type 'NSTextField' has no member 'selectedRange'
Apr ’20
Reply to currentEditor
1. What is the original myKeyDown that you override ?The NSWindowConroller is a subclass of a baseClass, but the super.myKeyDow is never called. So the override keyword has no importanceThe myKeyDow is called by the following mechanism:_eventMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { if self.myKeyDown(with: $0) { return nil } else { return $0 } }2 What is ctrlRch ? a textField I guess? What is the currentDitor doing ?ctrlRch is a subclass of NSTextField and I just want it to get the focus when the user tap a key on his keyboard.the current editor, as referred to the apple dcumentation returns the field editor for the currentControl or nil if the receiver does not have a field editor.In my case, I always get nil for fieldEditor invar fieldEditor = ctrlRch.currentEditor()3. Where do you set focus to the textField ?I'm not sure but I think that the following code put the focus on ctrlRch:window?.makeFirstResponder(ctrlRch)In fact, if in my subclassed ctrlRchI write the function becomeFirstResponder and resigneFirstResponder, I can see that when I call makeFirstResponder in my controller, becomeFirstResponder is called and immediatly resigneFirstResponder is called4. Do you get a print logged when you type a char ?I'm not sure waht you mean, but if I writeSwift.print(event.description)I have a log of each key pressed
Apr ’20
Reply to Array function and generic types
I think you are rightThe declaration of the fetch function as simply to be:func fetch(_ tableview: NSTableView, _ row: Int, params: Parameters, response: ResponseListModel&lt;T&gt;.Type, completion: @escaping (Bool) -&gt; Void) {}in this case, the compiler acceptsself.moderators.insert(contentsOf: rep.moderators, at: 0)
Feb ’20
Reply to Array function and generic types
No of course it isn't the real codeI wanted to isolate the response of the compilerThe Code is quite complexclass ResponseListModel: Decodable { var moderators: [T] var totalEnreg: Int var hasMore: Bool var currentPage: Int var indexPage: Int = 0 var limit: Int = 0 var nbPagesInMemory: Int! var fetchingData: Bool = true enum CodingKeys: String, CodingKey { case moderators = "items" case hasMore = "has_more" case totalEnreg = "total" case currentPage = "page" } func destroyPageData(_ index: Int) { moderators.removeSubrange(index..&lt;index+min(limit, moderators.count))&lt;br=""&gt; } func rowLoaded (_ row: Int) -&gt; Bool { let firstIndex = (currentPage-1)*limit let lastIndex = firstIndex + moderators.count return row &gt;= firstIndex &amp;&amp; row &lt; lastIndex } func rowIndex (_ row: Int) -&gt; Int { return row - (currentPage - 1)*limit } func row(_ row: Int) -&gt; T { let rowCalculee = row - (currentPage-1)*limit return moderators[rowCalculee] } func clean() { moderators.removeAll() } func fetch(_ tableview: NSTableView, _ row: Int, params: Parameters, response: ResponseListModel.Type, completion: @escaping (Bool) -&gt; Void) where T: Decodable { Swift.print("ca tourne pour row=\(row)") if !fetchingData /*|| !rowLoaded(row)*/ { fetchingData = true // 1 calculate what part of the array has to be destroyed if row &lt; indexPage { destroyPageData((nbPagesInMemory-1)*limit) } else { destroyPageData(0) self.indexPage += limit } // 2 Fetch data if necessary StackExchangeClient().fetch(request: BaseRequest(parameters: params), dataResponse: response, completion: { result in switch result{ case .failure(_): completion(false) case .success(let response): let rep = response as! ResponseListModel self.currentPage += rep.moderators.count / self.limit if row &lt; self.indexPage { self.moderators.insert(rep.moderators, at: 0) } else { self.moderators.insert(contentsOf: rep.moderators, at: self.moderators.count) } self.moderators.append(rep.moderators) let rows = NSIndexSet(indexesIn: NSMakeRange(row, self.indexPage+self.moderators.count-1)) as IndexSet let cols = NSIndexSet( indexesIn: NSMakeRange(0, tableview.numberOfColumns)) as IndexSet DispatchQueue.main.async { self.fetchingData = false tableview.reloadData(forRowIndexes: rows, columnIndexes: cols) } completion(true) } }) } }I can't correctly reproduce the header of the fetch function with the advance.button of this forum, it corrects the codemy code isfunc fetch&lt;T&gt;(_ tableview: NSTableView, _ row: Int, params: Parameters, response: ResponseListModel&lt;T&gt;.Type, completion: @escaping (Bool) -&gt; Void) where T: Decodable {}and my problem appears on lines 63 and 65
Feb ’20
Reply to NSWiewController
You are right, I chosse the firstbecause one thing I didn't told is that my application is document based so I can have multiple splitview and multiple toolbars.That"s why I was looking for the ancestorThank's
Jan ’20