問(wèn)題描述
我正在使用 nib 文件加載視圖:
I am loading a view from a nib file using:
nib 包含一個(gè)名為 gridScrollView 的滾動(dòng)視圖,在 AnalysisView 實(shí)現(xiàn)文件中,我有一個(gè)將視圖作為子視圖添加到滾動(dòng)視圖的方法:
The nib contains a scrollview called gridScrollView and in the AnalysisView implementation file I have a method which adds views as subviews to the scrollview:
我已將滾動(dòng)視圖委托設(shè)置為 AnalysisView 并連接了 do end decelaring 方法
I have set the scrollviews delegate to be AnalysisView and hooked up the did end decelaring method
當(dāng) scrollViewDidEndDecelerating 方法觸發(fā)時(shí),它報(bào)告子視圖的數(shù)量是 5.這些子視圖中的 3 個(gè)是我期望的 GridView.但是有 2 個(gè) UIImageViews 我不知道它們?yōu)槭裁丛谀抢?
When the scrollViewDidEndDecelerating method fires it reports that the number of subviews is 5. 3 of these subviews are GridViews which I expect. However there are 2 UIImageViews which I have no idea why they are there.
這是一個(gè)問(wèn)題,因?yàn)槲掖蛩阍?scrollViewDidEndDecelerating 方法中使用 viewWithTag 檢索視圖并在視圖上調(diào)用一個(gè)方法,但是每當(dāng)我嘗試檢索標(biāo)簽為 0 的視圖時(shí),我都會(huì)檢索其中一個(gè) UIImageView 和 this導(dǎo)致我的應(yīng)用程序崩潰,因?yàn)闊o(wú)法在圖像視圖上調(diào)用該方法.
This is an issue because I intend on retrieving the views with viewWithTag in the scrollViewDidEndDecelerating method and calling a method on the view, however whenever I try to retrieve a view with a tag of 0 I will retrieve one of the UIImageView's and this causes my app to crash because the method cannot be called on an image view.
我知道一種解決方法是將我的 GridView 存儲(chǔ)在一個(gè)單獨(dú)的實(shí)例數(shù)組中并從那里引用它們.但我很想知道這 2 個(gè) UIImageView 是什么以及它們是如何到達(dá)那里的.
I know a way round this is to store my GridViews in a seperate instance array and reference them from there. But I'm curious to know what the 2 UIImageViews are and how they got there.
推薦答案
UIScrollView
默認(rèn)包含 2 個(gè) UIImageViews
作為滾動(dòng)指示器的子視圖.雖然我在文檔中找不到任何關(guān)于滾動(dòng)指示器實(shí)現(xiàn)的具體信息,但這些圖像視圖存在于類聲明中(參見(jiàn) UIScrollView.h
標(biāo)頭):
UIScrollView
by default contains 2 UIImageViews
as subviews for scroll indicators. Although I can't find anything specific about scroll indicators implementation in docs, those imageviews are present in class declaration (see UIScrollView.h
header):
您也可以不從 0 開(kāi)始分配標(biāo)簽,而是從某個(gè)正數(shù)開(kāi)始 - 這樣可以避免與標(biāo)準(zhǔn)子視圖發(fā)生沖突
You can also start assigning tags not from 0, but from some positive number - that way avoiding collision with standard subviews
這篇關(guān)于UIScrollView 幻象子視圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!