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

Xcode 15 Beta3加载含分段控件Xib崩溃:_UIRecessedMaterialView未找到

问题:Xcode 15 Beta3编译后,iOS/iPadOS 17加载含UISegmentedControl的Xib崩溃,找不到_UIRecessedMaterialView类

使用Xcode 15 Beta3编译App,加载包含UISegmentedControl的Xib文件时,在iPadOS 17设备或iOS 17模拟器上启动即崩溃,抛出NSInvalidUnarchiveOperationException异常,提示无法实例化_UIRecessedMaterialView类(该类未找到)。该问题在iOS 16.3.1上不会出现。

崩溃调用栈

Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UIRecessedMaterialView because no class named _UIRecessedMaterialView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'
0   CoreFoundation                      0x00007ff80048c88a __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007ff800057894 objc_exception_throw + 48
2   CoreFoundation                      0x00007ff80048c768 -[NSException initWithCoder:] + 0
3   UIFoundation                        0x00007ff804a1eb4d UINibDecoderDecodeObjectForValue + 352
4   UIFoundation                        0x00007ff804a1eebe UINibDecoderDecodeObjectForValue + 1233
5   UIFoundation                        0x00007ff804a1e9e2 -[UINibDecoder decodeObjectForKey:] + 257
6   UIKitCore                           0x0000000108c04a9f -[UIView initWithCoder:] + 1327
7   UIKitCore                           0x0000000107c32c81 -[UIControl initWithCoder:] + 65
8   UIKitCore                           0x0000000107c5a7b3 -[UISegmentedControl initWithCoder:] + 65
9   UIFoundation                        0x00007ff804a1ecb4 UINibDecoderDecodeObjectForValue + 711
10  UIFoundation                        0x00007ff804a1e9e2 -[UINibDecoder decodeObjectForKey:] + 257
11  UIKitCore                           0x000000010801c7cd -[UIRuntimeConnection initWithCoder:] + 125
12  UIKitCore                           0x000000010801cbef -[UIRuntimeEventConnection initWithCoder:] + 59
13  UIFoundation                        0x00007ff804a1ecb4 UINibDecoderDecodeObjectForValue + 711
14  UIFoundation                        0x00007ff804a1eebe UINibDecoderDecodeObjectForValue + 1233
15  UIFoundation                        0x00007ff804a1e9e2 -[UINibDecoder decodeObjectForKey:] + 257
16  UIKitCore                           0x0000000108015a79 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsWithSourceSegueTemplate:creator:sender:forKey:] + 447
17  UIKitCore                           0x000000010801877e -[UINib instantiateWithOwner:options:] + 1118
18  UIKitCore                           0x000000010801a112 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 139
19  CustomSearchBarBug                  0x000000010671830e $s18CustomSearchBarBug11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0m6LaunchL3KeyaypGSgtF + 462
20  CustomSearchBarBug                  0x0000000106718687 $s18CustomSearchBarBug11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0m6LaunchL3KeyaypGSgtFTo + 183
21  UIKitCore                           0x000000010857a092 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 297
22  UIKitCore                           0x000000010857be6b -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4253
23  UIKitCore                           0x000000010858196b -[UIApplication _runWithMainScene:transitionContext:completion:] + 1241
24  UIKitCore                           0x00000001078e6780 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 181
25  UIKitCore                           0x000000010857e1dc -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
26  UIKitCore                           0x000000010857e591 -[UIApplication _run] + 936
27  UIKitCore                           0x000000010858301a UIApplicationMain + 123
28  UIKitCore                           0x000000010764e103 __swift_destroy_boxed_opaque_existential_1Tm + 10851
29  CustomSearchBarBug                  0x0000000106718b1b $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 123
30  CustomSearchBarBug                  0x0000000106718a97 $s18CustomSearchBarBug11AppDelegateC5$mainyyFZ + 39
31  CustomSearchBarBug                  0x0000000106718b88 main + 24
32  dyld                                0x00000001068a23ee start_sim + 10
33  ???                                 0x000000010dfd041f 0x0 + 4529652767
)
libc++abi: terminating due to uncaught exception of type NSException

可重现的Xib代码

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="22138.1" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
    <device id="ipad7_9" orientation="portrait" layout="fullscreen" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22113"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view clipsSubviews="YES" contentMode="scaleToFill" id="63">
            <rect key="frame" x="0.0" y="0.0" width="744" height="1133"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
            <subviews>
                <segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="10">
                    <rect key="frame" x="218.5" y="5.5" width="331" height="33"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <segments>
                        <segment title="Item"/>
                        <segment title="Brand"/>
                    </segments>
                    <connections>
                        <action selector="segmentedControlChanged:" destination="-1" eventType="valueChanged" id="25"/>
                    </connections>
                </segmentedControl>
            </subviews>
            <nil key="simulatedStatusBarMetrics"/>
            <point key="canvasLocation" x="467.96875" y="146.484375"/>
        </view>
    </objects>
</document>

Xib加载代码

let nibs = Bundle.main.loadNibNamed("SegmentedControl", owner: nil, options: nil)

修复方案
  • 移除Xib中UISegmentedControl的segmentControlStyle="bar"属性
    直接编辑Xib的XML代码,删除<segmentedControl>标签里的segmentControlStyle="bar"属性;或者在Interface Builder中,将UISegmentedControl的Style从"Bar"切换为"Plain"等其他样式,重新编译即可解决崩溃。

  • 改用代码创建UISegmentedControl
    放弃在Xib中配置控件,通过纯代码初始化并添加到视图:

    import UIKit
    
    // 在合适的位置(比如viewDidLoad)创建控件
    let segmentedControl = UISegmentedControl(items: ["Item", "Brand"])
    segmentedControl.frame = CGRect(x: 218.5, y: 5.5, width: 331, height: 33)
    segmentedControl.addTarget(self, action: #selector(segmentedControlChanged(_:)), for: .valueChanged)
    self.view.addSubview(segmentedControl)
    
    // 对应的回调方法
    @objc func segmentedControlChanged(_ sender: UISegmentedControl) {
        // 处理选中逻辑
    }
    
  • 等待Xcode更新
    这是Xcode 15 Beta版本的兼容性Bug,苹果通常会在后续Beta版本或正式版中修复,可关注Xcode更新日志,升级后验证问题是否解决。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 18:01:57