代碼學(xué)習(xí)

1. UICollectionViewLayout 的 prepareLayout 方法

// The collection view calls -prepareLayout once at its first layout as the first message to the layout instance.
collectionview會(huì)在第一次布局時(shí),調(diào)用 prepareLayout 方法一次,作為創(chuàng)建 layout 的第一個(gè)對(duì)象.

// The collection view calls <font color=red>-prepareLayout</font> again after layout is invalidated and before requerying the layout information.
collectionview 再次調(diào)用 prepareLayout 方法時(shí),是在 layout 失效或者重新查詢 layout 信息.

// Subclasses should always call super if they override.
子類必須調(diào)用父類的 prepareLayout 方法.

2. UICollectionViewLayout 的 layoutAttributesForElementsInRect 方法

// UICollectionView calls these four methods to determine the layout information.
UICollectionView調(diào)用以下4個(gè)方法來決定布局信息

// Implement -layoutAttributesForElementsInRect: to return layout attributes for for supplementary or decoration views, or to perform layout in an as-needed-on-screen fashion.
實(shí)現(xiàn) layoutAttributesForElementsInRect 方法來給 頭視圖或尾視圖或裝飾視圖 返回 layout 布局屬性,或者來實(shí)現(xiàn)按需顯示到屏幕上的策略

// Additionally, all layout subclasses should implement -layoutAttributesForItemAtIndexPath: to return layout attributes instances on demand for specific index paths.
額外的,所有的子類必須實(shí)現(xiàn) layoutAttributesForItemAtIndexPath 方法來創(chuàng)建 layout 布局屬性 以便實(shí)現(xiàn)特殊的行的需求.

// If the layout supports any supplementary or decoration view types, it should also implement the respective atIndexPath: methods for those types.
如果布局支持任何 頭視圖/尾視圖或裝飾視圖類型,那么也要實(shí)現(xiàn)各自的atIndexPath:方法.
(PS:應(yīng)該是代理方法collectionView:viewForSupplementaryElementOfKind:atIndexPath:方法)

3. 使用內(nèi)購時(shí) , 必須有恢復(fù)未完成訂單的程序

We still found that your app uses intermediary currency to purchase items that function as non-consumable products but does not include a restore mechanism.
///我們?nèi)匀话l(fā)現(xiàn)虫啥,你的應(yīng)用程序使用中間貨幣來購買功能非消費(fèi)品的商品,但不包括恢復(fù)機(jī)制单匣。

Users restore transactions to maintain access to content that they've already purchased.
/// 用戶恢復(fù)事務(wù)以維護(hù)他們已經(jīng)購買的內(nèi)容的訪問權(quán)豁鲤。

4. 快速定位代碼位置

  1. tip 1: 通過 Charles 攔截接口,在代碼中查找對(duì)應(yīng)請(qǐng)求該接口的網(wǎng)絡(luò)請(qǐng)求類, 在其回調(diào)中查找配置的視圖或操作.
  2. tip 2: 運(yùn)行程序, 通過層次結(jié)構(gòu), 查找頁面的名稱, 定位具體的位置, 如TimeTaskView —> GetBambooView —> GetBambooView —> gainBamboos.
  3. tip 3: 在找不到點(diǎn)擊事件的時(shí)候, 可以在點(diǎn)擊后必須會(huì)調(diào)用的方法中插入斷點(diǎn), 通過調(diào)用過程, 反推點(diǎn)擊事件的原始地方.
  4. tip 4: 類似于修電腦的方法, 找一個(gè)正確的 UI 和有 bug 的UI進(jìn)行比較, 找出其中的異常.

5. 改 bug 的一些方法

  1. 高度或間距問題: 改 collectionview 的間距, 可以把layout:sizeForItemAtIndexPath: 方法返回的值, 全部改成無限大或無限小(先不管 section), 如果依舊沒什么用, 可以把layout:insetForSectionAtIndex:方法的值全部改成無限大或無限小(先不管 section), 也就是不計(jì)后果的那種.
  2. 重疊問題: A頁面繼承于 B 頁面, A 的頁面明顯超出了 B 的位置 ===> 全局搜索 super 方法, 只有initWithFrame:方法中有 super, 因此需要在創(chuàng)建 A 或 B 時(shí), 各自單獨(dú)調(diào)用initWithFrame:中的方法 ==> 原因是 A 繼承了 B 的視圖, 自己也創(chuàng)建了一份, 但是只給 A 的視圖賦值并更新位置, 沒有給 B 的視圖賦值和更新位置.

6. 快速獲取頂部控制器

在 UIViewController 中很深的子視圖中, 需要調(diào)用UIViewController進(jìn)行跳轉(zhuǎn), 可以直接在當(dāng)前子視圖中遍歷當(dāng)前窗口的根控制器的最外層控制器, 找到后就直接跳轉(zhuǎn).

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
    if ([rootViewController isKindOfClass:[PTVSideMenuViewController class]])
    {
        PTVSideMenuViewController *sideMenuVc = (PTVSideMenuViewController *)rootViewController;
        return [self topViewControllerWithRootViewController:sideMenuVc.rootViewController];
    }
    else if ([rootViewController isKindOfClass:[UITabBarController class]]) {
        UITabBarController* tabBarController = (UITabBarController*)rootViewController;
        return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
    } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController* navigationController = (UINavigationController*)rootViewController;
        return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
    } else if (rootViewController.presentedViewController) {
        UIViewController* presentedViewController = rootViewController.presentedViewController;
        return [self topViewControllerWithRootViewController:presentedViewController];
    } else {
        return rootViewController;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末祟牲,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌侠讯,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,826評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件暑刃,死亡現(xiàn)場(chǎng)離奇詭異厢漩,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)岩臣,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門溜嗜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人架谎,你說我怎么就攤上這事炸宵。” “怎么了狐树?”我有些...
    開封第一講書人閱讀 164,234評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵焙压,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我抑钟,道長(zhǎng)涯曲,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,562評(píng)論 1 293
  • 正文 為了忘掉前任在塔,我火速辦了婚禮幻件,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蛔溃。我一直安慰自己绰沥,他們只是感情好篱蝇,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,611評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著徽曲,像睡著了一般零截。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上秃臣,一...
    開封第一講書人閱讀 51,482評(píng)論 1 302
  • 那天涧衙,我揣著相機(jī)與錄音,去河邊找鬼奥此。 笑死弧哎,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的稚虎。 我是一名探鬼主播撤嫩,決...
    沈念sama閱讀 40,271評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼蠢终!你這毒婦竟也來了序攘?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,166評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤蜕径,失蹤者是張志新(化名)和其女友劉穎两踏,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體兜喻,經(jīng)...
    沈念sama閱讀 45,608評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡梦染,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,814評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了朴皆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片帕识。...
    茶點(diǎn)故事閱讀 39,926評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖遂铡,靈堂內(nèi)的尸體忽然破棺而出肮疗,到底是詐尸還是另有隱情,我是刑警寧澤扒接,帶...
    沈念sama閱讀 35,644評(píng)論 5 346
  • 正文 年R本政府宣布伪货,位于F島的核電站,受9級(jí)特大地震影響钾怔,放射性物質(zhì)發(fā)生泄漏碱呼。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,249評(píng)論 3 329
  • 文/蒙蒙 一宗侦、第九天 我趴在偏房一處隱蔽的房頂上張望愚臀。 院中可真熱鬧,春花似錦矾利、人聲如沸姑裂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽舶斧。三九已至欣鳖,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間茴厉,已是汗流浹背观堂。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留呀忧,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,063評(píng)論 3 370
  • 正文 我出身青樓溃睹,卻偏偏與公主長(zhǎng)得像而账,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子因篇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,871評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容