You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS端PDFTron移除ThumbnailViewController编辑按钮及架构适配问题咨询

Solution for Two PDFTron iOS Issues: Hiding Thumbnail Edit/Delete Buttons & Framework Architecture Mismatch

1. Removing Edit/Delete Buttons in ThumbnailViewController

Since you can't modify the source ThumbnailsViewController.m directly in the dynamic framework, you have two reliable workarounds using Objective-C runtime or view inspection:

  • Option 1: Method Swizzling to Override Setup
    You can use method swizzling to intercept the view setup of the ThumbnailsViewController and remove/hide the edit button. Here's a practical implementation:

    #import <objc/runtime.h>
    #import <PDFNet/PDFNet.h>
    
    @implementation ThumbnailViewControllerSwizzler
    
    + (void)load {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            Class targetClass = NSClassFromString(@"ThumbnailsViewController");
            SEL originalSel = @selector(viewDidLoad);
            SEL swizzledSel = @selector(swizzled_viewDidLoad);
    
            Method originalMethod = class_getInstanceMethod(targetClass, originalSel);
            Method swizzledMethod = class_getInstanceMethod([self class], swizzledSel);
    
            BOOL didAddMethod = class_addMethod(targetClass, originalSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
            if (didAddMethod) {
                class_replaceMethod(targetClass, swizzledSel, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
            } else {
                method_exchangeImplementations(originalMethod, swizzledMethod);
            }
        });
    }
    
    - (void)swizzled_viewDidLoad {
        [self swizzled_viewDidLoad]; // Execute original setup logic
        // Filter out the edit/delete button from navigation bar
        NSMutableArray *filteredBarItems = [NSMutableArray array];
        for (UIBarButtonItem *item in self.navigationItem.rightBarButtonItems) {
            if (![item.title isEqualToString:@"Edit"] && item.action != @selector(toggleEditing:)) {
                [filteredBarItems addObject:item];
            }
        }
        self.navigationItem.rightBarButtonItems = filteredBarItems;
    }
    
    @end
    

    Add this category to your project — it will automatically modify the ThumbnailsViewController's navigation bar when it loads.

  • Option 2: Observe View Appearance to Modify Buttons
    If swizzling feels too invasive, you can listen for when the thumbnail view controller appears, then adjust its navigation items:

    // Add this in your app delegate or parent view controller
    [[NSNotificationCenter defaultCenter] addObserverForName:UIViewControllerDidAppearNotification 
                                                      object:nil 
                                                       queue:[NSOperationQueue mainQueue] 
                                                  usingBlock:^(NSNotification *note) {
        UIViewController *vc = note.object;
        if ([vc.class.description isEqualToString:@"ThumbnailsViewController"]) {
            NSMutableArray *cleanedItems = [NSMutableArray array];
            for (UIBarButtonItem *item in vc.navigationItem.rightBarButtonItems) {
                if (![item.title isEqualToString:@"Edit"]) {
                    [cleanedItems addObject:item];
                }
            }
            vc.navigationItem.rightBarButtonItems = cleanedItems;
        }
    }];
    

2. Fixing "no matching architecture in universal wrapper" Error for Tools.framework

This error occurs because your custom-built Tools.framework lacks the arm64 architecture required for physical iOS devices (simulators use x86_64/arm64 simulator architectures). Follow these steps to fix it:

  • Step 1: Verify Framework Architectures
    Open Terminal, navigate to your framework's directory, and run:

    lipo -info Tools.framework/Tools
    

    If arm64 isn't listed, that's the root cause.

  • Step 2: Recompile for All Required Architectures
    When building the PDFTron Tools framework in Xcode:

    1. Select the Tools target, go to Build Settings > Architectures.
    2. Set Valid Architectures to include arm64, armv7 (if supporting older devices).
    3. Set Build Active Architecture Only to NO for both Debug and Release configurations.
    4. Build separately for Simulator and Physical Device, then merge the binaries with:
      lipo -create /path/to/simulator/Tools.framework/Tools /path/to/device/Tools.framework/Tools -output /path/to/universal/Tools.framework/Tools
      
  • Step 3: Adjust App Project Settings
    In your app's Build Settings:

    • Set Excluded Architectures to i386 and x86_64 for the Release (Universal Device) configuration.
    • Ensure Always Embed Swift Standard Libraries is set to YES (if the framework uses Swift).
  • Step 4: Clean and Rebuild
    Clean your project (Cmd+Shift+K), delete derived data, then rebuild the app for the universal device target.


内容的提问来源于stack exchange,提问作者Nikhil Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:57:09