contextMenuConfigurationForItemsAtIndexPaths for UITableView? - ios

We know that iOS 13 adds the ContextMenu function to UITableView, we can use the following method to display the context menu of UITableViewCell:
- (nullable UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point
But how can we show a menu for multiple selected rows? Like the "Files" app?
Starting with iOS 16, the UICollectionView added this:
- (nullable UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionView
contextMenuConfigurationForItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
point:(CGPoint)point
It's strange that UITableView doesn't have this function, did Apple forget to do it? :)
Is there a way to achieve the same for UITableView ? Or am I missing something?
Is there a way to achieve the same for UITableView?

Related

How to add section header/footer view when using AsyncDisplayKit?

It seems that currently ASTableNode and ASTableView both lack the support of section header/footer view.
I cannot only find a protocol method:
- (nullable NSString *)tableNode:(ASTableNode *)tableNode titleForHeaderInSection:(NSInteger)section
which shows nothing.
And the delegate/dataSource setter methods have been intercepted by AsyncDisplayKit, so that I cannot use the UIKit's way to do it.
So can I add section header/footer view when I'm using AsyncDisplayKit?
Just find out that ASTableNode will call the UITableViewDelegate methods.
So just implement the methods
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
And it will work just like before.

Create a collectionView from an existing tableView data source and controller

So i've been working on an ePub framework called Readium and they recently created an SDK for IOS.
The SDK is a full working project that allows a user to select an ePub from a tableView list and after selecting one gives you meta-data about that ePub after which you have to select the page list or spine items and after selecting one of the pages it finally goes to the ePub.
I want to streamline this process by opening with a list of ePubs in a collectionView and after selecting an ePub make it go straight to the first/cover page of that ePub.
What I want to know is if it is possible to use the viewController and data sources of the tableView to create a new collectionView? I have already adapted this project to allow Swipe Navigation.
It is possible to do it quite quickly.
1) You have to tell the controller that you want to adapt collection view, so you have two options in your .h file:
a) If you are currently inheriting from UITableView - inherit your ViewController from UICollectionViewController:
#interface YouViewControllerName : UICollectionViewController
b) If you inherit from UIViewController, just set your controller conforming to CollectionView delegate and dataSource methods like this
#interface YouViewControllerName : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource> { ... }
2) Then you need to replace table view delegate and data source methods with collection view data source and delegate methods, so you need to replace something like this:
Old:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { ... }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { ... }
New:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath { ... }
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section { ... }
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { ... }
So the content within your previous delegate/datasource methods could remain same, as the logic is not needed to change.
You may need to implement some more specific methods and to have some work with designing right item cell sizes etc., but is is natural as your layout is replaced by collection view.

Static TableViewControllers cells UI don't show up when connected to a controller

I am running into a strange problem regarding Uitableview cells in Xcode 6 iOS8. When I create a tableViewController from storyboard and choose static cells, the view shows up as it suppose to. However, when I connect that same view to a TableViewController source, the cells disappear. I connected all necessary things (reusable cell_ID, etc). Anyone experience this? This used to work for me previously. Thanks in advance!
Make sure that you don't implement any of UITableViewDatasourceDelegate methods in your TableViewController such as these methods below.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}

UITableView: first tap of the cell not received

I have UITableView on UIViewController with content a little bit larger then table's area. When I try to set bounces property to NO, the first tap of the cell stopes to receive after scrolling table to bounds.
I created a test project to receive all nuances of this problem:
1) first selection works fine before scrolling;
2) second selection after scrolling works fine too;
3) there is no problem, if scroll comes to the bounds itself (instead i'll scroll with finger and will end touch after came to the bounds);
4) set bounces property to YES solves problem (bcs scroll can comes to the bounds only itself);
5) highlights of the cell works always;
6) next delegate methods not received (ofcourse only when bug fired)
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
UPD: here's gif with bug, seems that scroll bar not hiding too, when this bug fires
Looks like an Apple's bug of UITableView that needs to report. Here some way to veil the problem (not good, but effective):
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (!scrollView.bounces) {
targetContentOffset->y = -1;
}
}

UITableView allowsMultipleSelectionDuringEditing for single section?

Is it possible to use the allowsMultipleSelectionDuringEditing property of a UITableView and have it apply to only 1 of several sections in a UITableView?
Yup!
see this delegate method
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

Resources