Post

Replies

Boosts

Views

Activity

Reply to How to pass reference to NSPersistentContainer to storyboard-created table view controller in objective c
Declare a initializer like this in your ToDoListTableViewController header file: -(instancetype)initWithCoder:(NSCoder*)coder persistentContainer:(NSPersistentContainer*)persistentContainer; Then in your implementation: -(instancetype)initWithCoder:(NSCoder*)coder persistentContainer:(NSPersistentContainer*)persistentContainer { self = [super initWithCoder:coder]; if (self) { _persistentContainer = persistentContainer; } return self; } Then you can do this: UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ToDoListTableViewController *toDOVC = [mainSB instantiateViewControllerWithIdentifier:@"ToDoListTableViewController" creator:^UIViewController * _Nullable(NSCoder * _Nonnull coder) { return [[ToDoListTableViewController alloc]initWithCoder:coder persistentContainer:persistentContainer]; }]; But I wouldn't stop there. You could make the code cleaner by also declaring a factory method in ToDoListTableViewController so you can write the UIStoryboard code from many different places: //In ToDoListTableViewController's header file: +(ToDoListTableViewController*)makeWithPersistentContainer:(NSPersistentContainer*)persistentContainer; //Implementation: +(ToDoListTableViewController*)makeWithPersistentContainer:(NSPersistentContainer*)persistentContainer; { UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; return [mainSB instantiateViewControllerWithIdentifier:@"ToDoListTableViewController" creator:^UIViewController * _Nullable(NSCoder * _Nonnull coder) { return [[ToDoListTableViewController alloc]initWithCoder:coder persistentContainer:persistentContainer]; }]; } Then you can just use the +makeWithPersistentContainer: to make the ToDoListTableViewController. Alternatively you could look for documentation on the hidden IBSegueAction feature but it's probably not necessary.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jun ’23
Reply to UIKit doesn't always retain custom UIViewControllerTransitioningDelegate?
Whoops made a mistake in the last code block in my previous post (can't edit it). It should be: theVC.modalPresentationStyle = UIModalPresentationCustom; theVC.transitioningDelegate = transDelegate; theVC.strongTransDelegate = transDelegate; I'm assuming the transitioningDelegate property was declared weak anticipating cases where someone would set self as the transitioningDelegate I guess.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jun ’23
Reply to Using SF Symbols on iOS 13 and falling back to assets on iOS 12
Adding a fallback image isn't working for me for iOS 14 ('m using a symbol introduced in iOS 15 and I'm getting this warning in a storyboard file). I tried: Adding a normal image asset with the same name as the symbol in my Asset catalog. Adding a "Symbol image set" with the same name as a symbol in my Asset catalog. Neither worked for me. The symbol has dots. like key.radiowaves.forward.fill
Topic: UI Frameworks SubTopic: UIKit Tags:
Jun ’23
Reply to UISheetPresentationController behind UITabBar
+1 for a sample. How does presenting a UITabBarController on top of the UISheetPresentationController make the sheet appear behind the tab bar but above the tab view controllers' content? Only thing I can think of is maybe adding a UITabBar (which is a view) to the sheet itself at the bottom. But then I'd have to basically reimplement UITabBarController functionality from scratch and this would be very disruptive to my app's current structure (probably not worth the effort). That would get the "Find My app" look (which has a sheet that can't be dismissed). In my case I need a sheet that is dismissible. I think a nice enhancement would be able to specify a passthrough view, or something of that nature on UISheetPresentationController. Something like: @property (nonatomic,strong,nullable) UITabBar *passThroughTabBar; So existing UITabBarControllers can easily add a sheet that doesn't block the tab bar. Or maybe something like this: @property (nonatomic,strong,nullable) CGFloat bottomMargin; //assign the UITabBar's frame height to this so it floats above the tab bar instead of covering it.
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’23
Reply to UITextView.scrollRangeToVisible() broken
UITextView -scrollRangeToVisible: wasn't working for me either. I have a UITextView and I'm trying to have it scroll to particular words. In my case I set the scrollEnabled property to NO on the UITextView because I need user scrolling to be disabled. For me the workaround was to set the scrollEnabled property back to YES and set the userInteractionEnabled property to NO. -scrollRangeToVisible: then started working but only sometimes. I had to change the text layout to TextKit1 as mentioned by @alexschecha to get the -scrollRangeToVisible: method to work properly. Unlike -setContentOffset: the -scrollRangeToVisible: method will only work if the scrollEnabled property is YES it seems and it will only work reliably under TextKit1 as far as I can tell. There is still a limitation though. I'd like to scroll the range to the middle of the UITextView. If the range is below the visible region of the UITextView then -scrollRangeToVisible: will scroll it to the bottom. I tried getting the frame for the range myself like so: UITextPosition *beginning = textView.beginningOfDocument; UITextPosition *start = [textView positionFromPosition:beginning offset:range.location]; UITextPosition *end = [textView positionFromPosition:start offset:range.length]; UITextRange *textRange = [textView textRangeFromPosition:start toPosition:end]; CGRect rect = [textView firstRectForRange:textRange]; CGRect finalRect = [textView convertRect:rect fromView:textView.textInputView]; textView.contentOffset = CGPointMake(0.0,finalRect.origin.y-visibleOffetY); And that works... sometimes. Every once and awhile the computed rect from the range will be CGRectNull (range is valid but I get CGRectNull anyway).
Topic: App & System Services SubTopic: Core OS Tags:
May ’23
Reply to UIDeferredMenuElement With Uncached Provider Not Working on Mac Catalyst. Uncached provider block never called and menu displays as "Loading"
Still not fixed in Ventura 13.3. Can you show your code so I can see what's different from mine? I tried using it with a UIButton instead of UIBarButtonItem and then adding it to my NSToolbar with NSUIViewToolbarItem but still not working. The menu just shows a "Loading..." item and the uncached provider block is never called.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’23
Reply to Crash on iOS 16.2: -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:
Yes I was able to resolve it. So in my case I have a dedicated object as the UITableViewDataSource that sits between the UIViewController and the UITableView. The object that I use as the table view data source implements everything needed to populate the table view data, refreshing it automatically on model changes, etc. The only thing my table view data source doesn't do was provide a UITableView cell in -tableView:cellForRowAtIndexPath: method (instead it asks its delegate for the cell, which is the UIViewController) . My data source object is sort of like UITableViewDiffableDataSource in this way. So what was happening is the UITableView AND the table view data source objects were occasionally outliving the UIViewController. Then when a model change notification is posted my datasource object asked the view controller for the cell in -tableView:cellForRowAtIndexPath: (but the view controller was already deallocated). Never was able to reproduce it in debug mode. I removed the delegate-protocol from my data source object and captured the cell creation code in a block property and I haven't had a crash since.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’23