首页 > 解决方案 > 为什么我不能访问这个指针的值。目标c

问题描述

我想访问YGNodeRef nodeRCTMeasure 函数的参数。这是来自 react-native 中的瑜伽文件,RCTShadowText.m

static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode 
widthMode, float height, YGMeasureMode heightMode)
{
  RCTShadowText *shadowText = (__bridge RCTShadowText *) 
  YGNodeGetContext(node);
  NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width 
  widthMode:widthMode];
  [shadowText calculateTextFrame:textStorage];
  NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
  NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
  CGSize computedSize = [layoutManager 
  usedRectForTextContainer:textContainer].size;

  YGSize result;
  result.width = RCTCeilPixelValue(computedSize.width);
  if (shadowText->_effectiveLetterSpacing < 0) {
     result.width -= shadowText->_effectiveLetterSpacing;
  }
  result.height = RCTCeilPixelValue(computedSize.height);
  return result;
 }

YGNodeRef 在另一个名为 Yoga.h 的类中被删除。

typedef struct YGNode *YGNodeRef;

我可以在调试器中看到 的值YGNodeRef node,但我不知道如何在代码中访问它的元素。内容如下所示:

(YGNodeRef) 0x150094a00
    > style (YGStyle)
    > layout (YGLayout)
    lineIndex = (uint32_t) 0
    > parent = (YGNodeRef) 0x15009e200
        ..... etc .....
    > context

我想访问“上下文”子项以检查它是否为空,非常感谢一些帮助。或者,如果您只是知道为什么上下文为 null 的原因,这也会对我有所帮助:)

我是 Objective C 的新手,所以我的逻辑可能有缺陷。

标签: objective-cxcodereactjsreact-nativepointers

解决方案


推荐阅读