iOS画外音: Focus selected cell and not the first row
<p><p>我试图让我的应用程序可访问,在我的界面中我有一个 UILabel 和一个 UITableView,tableView 有一个 selectedRow。 selectedRow 是表格 View 中间的行,例如如果我有 100 行,则为第 50 行。</p>
<p>我的问题是当我在屏幕上滑动以转到下一个元素时,在这种情况下,当我从标签转到 tableView 时,焦点转到第一个索引而不是我的单元格。</p>
<p>我该如何解决这个问题?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>假设您只有一个标签和一个表格 View ,问题归结为当您从标签移动到表格 View 时要记住单元格的最新位置。</p>
<p>以下算法可以用来解决这个问题:</p>
<ul>
<li>创建一个临时索引路径变量 (<code>tmpIP</code>),其中包含所选单元格的索引路径。</li>
<li>当标签失去焦点时,表格 View 会选择具有最新 <code>tmpIP</code> 索引路径的单元格。如果在选择标签之前没有选择任何单元格,则变量值为 nil。</li>
</ul>
<p> <a href="/image/qCSM4.png" rel="noreferrer noopener nofollow"><img src="/image/qCSM4.png" alt="enter image description here"/></a> </p>
<p>看看<code>UIAccessibilityFocus</code> <a href="https://developer.apple.com/documentation/uikit/accessibility/uiaccessibilityfocus" rel="noreferrer noopener nofollow">informal protocol</a>处理可访问元素的焦点。</p></p>
<p style="font-size: 20px;">关于iOS画外音: Focus selected cell and not the first row,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/53542890/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/53542890/
</a>
</p>
页:
[1]