UITableView Pointer Support for iPad using Objective-C

In iPadOS 13.4, Apple introduced the Mouse support for iPads. Prior to this mouse support had kind-of worked with iPads – I’d tried connecting a USB mouse using the Camera adaptor – but it was a bit flaky and didn’t really provide any feedback on what was clickable.

Fast-forward to 13.4, and now we had a circular pointer and feedback when the pointer was over a clickable item.

For most controls, it was simply a case of adding isPointerInteractionEnabled=yes to the control. However, for some other controls, such as UITableCellView, some custom code was required.

When I attempted to add this to iSMARTtrain for iOS, most, if not all, of the code I found was for Swift. It took a bit of time figuring out how to convert this to Objective-C (and I wasn’t about to rewrite an entire class just to for pointer support!). Here’s the code in case it helps anyone else.

For UITableView

In the View Controller, add the delegate:

@interface YFTListViewTableController : UITableViewController <UIPointerInteractionDelegate>

In the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method, add

if (@available(iOS 13.4, *)) {
  if (cell.interactions.count == 0) {
    UIPointerInteraction *pointerInteraction = [[UIPointerInteraction alloc] initWithDelegate:self];
    [cell addInteraction:pointerInteraction];
  }
}

Where cell is the cell for the row

Add the delegate method to the class

- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region  API_AVAILABLE(ios(13.4)){
    UIPointerStyle *pointerStyle = nil;
    
    UIView *interactionView = interaction.view;
    if (interactionView) {
        UITargetedPreview *targetPreview = [[UITargetedPreview alloc] initWithView:interactionView];
        
        
        UIPointerEffect *hoverEffect = [UIPointerHoverEffect effectWithPreview:targetPreview];
        
        pointerStyle = [UIPointerStyle styleWithEffect:hoverEffect shape:nil];
    }
    return pointerStyle;
}

YFCalendarView – iPad Calendar Framework

YFCalendarView is our open-source framework for a full-screen iPad calendar. It’s loosely based on the Mac calendar framework LRCalendar (which seems to have largely disappeared from the ‘net).

It provides a full-screen monthly calendar, functionally similar to the iPad Calendar app ‘Month’ view.

YFCalendarSmall

Download the latest code from our Github repository: http://github.com/tevendale/YFCalendar

iOS Debugging with Hardware

dockstubz from CableJive

If you’re developing an app which uses hardware that plugs into the 30-pin Dock Connector of the iPhone or iPad, then debugging in Xcode can become a bit of a problem. I’m working with Wahoo Fitness using their Fisica ANT+ device at the moment, and I was about to break out the soldering iron to make some sort of a pass-through connector when Chip from Wahoo mentioned using dockStubz from Cablejive.

This provides a male and female dock connector with a USB connector in the middle of the unit. This lets the iOS device be connected to a Mac with the hardware device installed, allowing breakpoints and the like to be set in Xcode.

It’s available directly from Cablejive in the US and from Amazon in the UK (and presumably the rest of Europe).