Post

Replies

Boosts

Views

Activity

Reply to Crash on iOS 16.2: -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:
UITableview is now very unstable on iOS 16.2. I see nothing in the iOS release notes that documents any changes to UIKit in the minor updates (16.1 and 16.2) but I'm now getting periodic crashes every day (usually once or twice a day) in my own use of my app which I use extensively every day and have for a very long time. All the crashes start with a method call from my app to -reloadData or -reconfigureRowsAtIndexPaths: and then stack trace looks like this: Last Exception Backtrace: 0 CoreFoundation 0x1d1069e48 __exceptionPreprocess + 164 1 libobjc.A.dylib 0x1ca33b8d8 objc_exception_throw + 60 2 Foundation 0x1cb92a94c _userInfoForFileAndLine + 0 3 UIKitCore 0x1d3380888 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 572 4 UIKitCore 0x1d344eeb4 -[UITableView _createPreparedCellForRowAtIndexPath:willDisplay:] + 68 5 UIKitCore 0x1d344ea9c -[UITableView _heightForRowAtIndexPath:] + 124 6 UIKitCore 0x1d344e938 -[UISectionRowData heightForRow:inSection:canGuess:] + 176 7 UIKitCore 0x1d3681394 -[UITableViewRowData heightForRow:inSection:canGuess:adjustForReorderedRow:] + 228 8 UIKitCore 0x1d328e8c4 -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:] + 304 9 UIKitCore 0x1d368091c -[UITableViewRowData rectForGlobalRow:heightCanBeGuessed:] + 112 10 UIKitCore 0x1d3681f70 -[UITableViewRowData globalRowsInRect:canGuess:] + 468 11 UIKitCore 0x1d36b43b8 -[_UITableViewUpdateSupport _faultInRealHeightsOfNeededElements] + 96 12 UIKitCore 0x1d36ee6c8 -[_UITableViewUpdateSupport _setupAnimations] + 36 13 UIKitCore 0x1d3524154 -[UITableView _updateWithItems:updateSupport:] + 832 14 UIKitCore 0x1d34e7ff0 -[UITableView _endCellAnimationsWithContext:] + 9900 15 UIKitCore 0x1d40ac6fc -[UITableView reconfigureRowsAtIndexPaths:] + 352 This has severely damaged the quality of my app. I'm trying to mitigate these crashes by reducing/deferring my calls to mutate the table view but it seems essentially impossible because I can't tell the table view to do anything (reload, reconfigure, etc.) without risking one of these crashes. I'd open a TSI on this but I can't reproduce the issue in the debug environment and my project is very large (I can't reproduce in a simple sample obviously because I can' reproduce it in my real project when attached to the debugger). The crash happens usually after hours of daily use. Doesn't look like an invalid index path is being passed to the table view, especially considering that I get these crashes shortly after a call to -reloadData which is supposed to completely sync the table view to my data source. I think someone with access to the UITableView source code can figure out what exception is being thrown here? I hope the changes made to UITableView will be reverted soon....
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’23
Reply to Crash on iOS 16.2: -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:
I can confirm that the exception being thrown here is "NSInternalInconsistencyException" with the Reason: UITableViewDataSource returned a nil cell for row at in index path" NSAssertFile = UITableView.m NSAssertLine = 16555 Since I couldn't reproduce this while attached to the debugger or when streaming logs from the app to Console I had to figure this out by writing the NSException related properties to a file in a function I pass to NSSetUncaughtExceptionHandler. Then I sent an Adhoc build to my device. After using the app for awhile I finally hit the crash. The crash report created looks identical to the ones I already shared in this thread and now I know the exception reason (not sure why the exception reason isn't included in the Crash Report?). As I previously mentioned I don't see a code path in my -tableView:cellForRowAtIndexPath: method the possibility of my app returning nil unless for some strange reason UITableView -dequeueReusableCellWithIdentifier:forIndexPath: returned nil in some odd circumstance to me.  What's interesting is that neither -tableView:cellForRowAtIndexPath: nor -dequeueReusableCellWithIdentifier:forIndexPath: appears in the call stack on any of these crash reports so I'm getting the feeling the exception is being thrown improperly and this is a UITableView bug introduced in a minor OS update. I'm going to add this to my -tableView:cellForRowAtIndexPath: method -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {     MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath]; //configure cell.. if (cell == nil) { //This is not good! Why? //Write a special file somewhere indicating that we have a nil cell right here. } return cell; } When the app crashes next time if this file exists I'll know for sure that UITableView improperly returned a nil cell to me..or if the exception message is completely bogus. But for now I got to get some sleep. This is not good.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’23
Reply to Crash on iOS 16.2: -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:
So after many days of using a new Adhoc build of my app with the change to write a file in the event of getting a nil cell in -tableView:cellForRowAtIndexPath: I failed to reproduce the crash. Finally I hit the crash again today. The file I attempt to write in -tableView:cellForRowAtIndexPath: does not exist on disk. The file I write to disk to capture the exception reason in my NSSetUncaughtExceptionHandler does exist. The exception reason is "UITableViewDataSource returned a nil cell for row at in index path" The exception message reason/message appears to be bogus (unless I just hit the lottery and my attempt to write a file in -tableView:cellForRowAtIndexPath: failed with an error). I think a few possibilities are: -UITableView exception message on this line 16555 is incorrect and needs to be changed to a proper exception message that truly indicates what's wrong. -UITableView is really hitting its reuse queue but isn't properly retaining the cell it thinks it has and when it gets nil back from its internal implementation, it is throwing an exception incorrectly instead of asking the delegate to make a new instance. -Maybe code triggered as part of inflight animations after delays/timers isn't properly cancelled when -reloadData is called and the table view is in a whacky state. Or something else. Impossible for me to know without source code. In any case I have no idea how I can workaround this issue using only public API. If my -tableView:cellForAtIndexPath: isn't returning nil....there doesn't seem to be a way I can fix this.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’23
Reply to UIMenuElement subclass that can take a target? Like UITargetedCommand?
Also this would be useful to specify targets outside the responder chain. For example I want to invoke an action from the menu bar on an object that isn't in the responder chain (it can be invoked even if my app has no open windows). As far as I can tell my only option is to use UIAction and call the method on the "target" in the actionHandler block. But what about validating the UIAction? -canPerformAction:withSender: won't be called on the object not in the responder chain. My best bet might be subclassing UIApplication and forwarding the method calls to the target I really want. Not sure why Apple seems to be abandoning targets. The UIKit APIs seem to be overusing blocks IMO.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’23
Reply to NSOpenPanel returning immediately in MacCatalyst
Wrapping NSOpenPanel/SavePanel in a bundle that can access the more powerful macOS APIs has its uses though. As far as I can tell there isn't a way to present UIDocumentInteractionController in the same way as NSOpenPanel -runModal. You need to present it from an existing UIViewController. Say you have an item in the menu bar that would invoke open or save and no windows are currently open (but the App is the menu bar owning app). In the Catalyst environment you can't present a freestanding UIDocumentInteractionController (unless I'm missing something?). First you need to create a window with a view controller, then present the UIDocumentInteractionController on the view controller which isn't ideal.
Topic: UI Frameworks SubTopic: AppKit Tags:
Jan ’23
Reply to How to define a Class instance type conforming to a protocol?
There is a class method flavor: +conformsToProtocol: https://developer.apple.com/documentation/objectivec/nsobject/1418893-conformstoprotocol From the documentation: Discussion A class “conforms to” a protocol if it adopts the protocol or inherits from another class that adopts it. Classes adopt protocols by listing them within angle brackets after the interface declaration. For example, here MyClass adopts the (fictitious) AffiliationRequests and Normalization protocols: @interface MyClass : NSObject <AffiliationRequests, Normalization> A class also conforms to any protocols included in the protocols it adopts or inherits. Protocols incorporate other protocols in the same way classes adopt them. For example, here the AffiliationRequests protocol incorporates the Joining protocol: @protocol AffiliationRequests <Joining> If a class adopts a protocol that incorporates another protocol, it must also implement all the methods in the incorporated protocol or inherit those methods from a class that adopts it. This method determines conformance solely on the basis of the formal declarations in header files, as illustrated above. It doesn’t check to see whether the methods declared in the protocol are actually implemented—that’s the programmer’s responsibility. To specify the protocol required as this method’s argument, use the @protocol() directive: BOOL canJoin = [MyClass conformsToProtocol:@protocol(Joining)]; Also note: Performance Considerations Calling this method in performance sensitive code can cause unwanted performance problems. conformsToProtocol: requires taking the Objective-C runtime lock and traversing the target’s class hierarchy to check for protocol conformance, which can take significant time. Consider the following alternatives in your code: Use respondsToSelector: to check for methods in the protocol instead, especially if you only need to check some of the protocol’s methods. If you do need to use conformsToProtocol:, cache the result whenever possible, rather than calling this method repeatedly.
Topic: Programming Languages SubTopic: General Tags:
Jan ’23
Reply to How to define a Class instance type conforming to a protocol?
Assuming I need to return an instance of a Class which conforms to this protocol from a method, how am I supposed to specify the return type? Like this... - (nullable id<TDWMethoding>)instantiateMethoding { Class instance = ... // some implementation if ([instance conformsToProtocol:@protocol(TDWMethoding)]) { return instance; } return nil; } If you want to return any object to the caller that conforms to the TDWMethoding protocol. Typically you'd do this if -instantiateMethoding may return objects of different classes but all those classes must conform to the protocol. If you just want to return an instance of a specific class and don't need it to be that generic just you do this: -(MyClass*)instantiateMethoding { //return it. } If MyClass conforms to the TDWMethoding protocol in its public header file you don't need to cast or write id<TDWMethoding> ... the compiler knows MyClass conforms to TDWMethoding. Not sure exactly what you're trying to do though. Hope that helps.
Topic: Programming Languages SubTopic: General Tags:
Jan ’23
Reply to NSOpenPanel returning immediately in MacCatalyst
Also UIDocumentInteractionController doesn't have any API that bridges to NSOpenPanel/NSSavePanel UI related properties like: @property (null_resettable, copy) NSString *prompt; /* NSSavePanel/NSOpenPanel: Gets and sets the title for the panel shown at the top of the window. */ @property (null_resettable, copy) NSString *title; /*  NSSavePanel: Gets and sets the text shown to the left of the "name field". Default value is a localized "Save As:" string.     NSOpenPanel: Not used. */ @property (null_resettable, copy) NSString *nameFieldLabel; Etc. etc. FWIW I'm not experiencing the OPs reported issue on Ventura 13.1.
Topic: UI Frameworks SubTopic: AppKit Tags:
Jan ’23
Reply to Crash on iOS 16.2: -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:
Perhaps I finally resolved this. My last guess is that the UITableView for some reason started outliving the object I use to return a cell in -tableView:cellForRowAtIndexPath: which was never the case prior to iOS 16.2. I made some changes, will need to test this longer to see if I finally got this fixed since the crash is pretty hard to reproduce.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’23
Reply to Mac Catalyst UITabBarController with hidden tab bar wrapping view controllers inside the "More" navigation controller (not desired) when 7 or more tabs are embedded
Hmm.. just for testing I showed the UITabBar and created a UITabBarItem for each view controller. UITabBarController just starts stacking view controllers in the "More" navigation controller when there are around 8 or more view controllers. It doesn't take into account the width of the UITabBarController; I can resize the window to giant size but the UITabBar just adds additional space between all the tab bar items and keeps the "More" item as the last tab bar item even though there is plenty of room to fit all tab bar items.
Topic: UI Frameworks SubTopic: UIKit Tags:
Feb ’23
Reply to Mac Catalyst UITabBarController with hidden tab bar wrapping view controllers inside the "More" navigation controller (not desired) when 7 or more tabs are embedded
Workaround is to do this in all the view controllers automatically being wrapped in the more navigation controller: -(void)willMoveToParentViewController:(UIViewController*)parent {   [super willMoveToParentViewController:parent]; #if TARGET_OS_MACCATALYST   if ([parent isKindOfClass:[UINavigationController class]])     { UINavigationController *navigationController = (UINavigationController*)parent;         [navigationController setNavigationBarHidden:YES]; } #endif }
Topic: UI Frameworks SubTopic: UIKit Tags:
Feb ’23