IOS開發基礎知識--碎片40

来源:http://www.cnblogs.com/wujy/archive/2016/05/24/5508797.html
-Advertisement-
Play Games

1:Masonry快速查看報錯小技巧 註意:MASAttachKeys會顯示出比較明瞭的錯誤信息; 2:iOS跳轉到系統設置 註意:想要實現應用內跳轉到系統設置界面功能,需要先在Targets-Info-URL Types-URL Schemes中添加prefs 3:UITableView sect ...


1:Masonry快速查看報錯小技巧

self.statusLabel = [UILabel new];
[self.contentView addSubview:self.statusLabel];
MASAttachKeys(self.statusLabel);

[self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(15.0f);
make.left.equalTo(self.contentView).offset(10.f);
make.height.equalTo(10);
make.bottom.equalTo(self.contentView);
}];

註意:MASAttachKeys會顯示出比較明瞭的錯誤信息;

 

2:iOS跳轉到系統設置

註意:想要實現應用內跳轉到系統設置界面功能,需要先在Targets-Info-URL Types-URL Schemes中添加prefs

跳轉到WIFI設置
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]])
{
        [[UIApplication sharedApplication] 
        openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
}

跳轉到藍牙
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]])
{
        [[UIApplication sharedApplication] 
        openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];
}

跳轉到通用
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURL URLWithString:@"prefs:root=General"]])
{
        [[UIApplication sharedApplication] 
        openURL:[NSURL URLWithString:@"prefs:root=General"]];
}

跳轉到關於本機
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURLURLWithString:
        @"prefs:root=General&path=About"]])
{
        [[UIApplication sharedApplication] 
        openURL:[NSURL URLWithString:@"prefs:
            root=General&path=About"]];
}


跳轉到定位服務
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURL URLWithString:@"prefs:
        root=LOCATION_SERVICES"]])
{
        [[UIApplication sharedApplication] 
        openURL:[NSURL URLWithString:@"prefs:
        root=LOCATION_SERVICES"]];
}


跳轉到通知
if ([[UIApplication sharedApplication] 
        canOpenURL:[NSURL URLWithString:@"prefs:
        root=NOTIFICATIONS_ID"]])
{
      [[UIApplication sharedApplication] 
      openURL:[NSURL URLWithString:@"prefs:
      root=NOTIFICATIONS_ID"]];
}

 3:UITableView section隨著cell滾動 

實現UITableView 的下麵這個方法,
#pragma mark - Scroll
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat sectionHeaderHeight = 40;
       //固定section 隨著cell滾動而滾動
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        
    }

}

 4:TableView如何刷新指定的cell 或section  

//一個section刷新    

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    

[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];    



//一個cell刷新    

NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];    

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];  

 5:TableView另一種實現隔行空白的效果

增加總體條數,然後再求餘判斷

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CELL_ID2 = @"SOME_STUPID_ID2";
    // even rows will be invisible
    if (indexPath.row % 2 == 1)
    {
        UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];

        if (cell2 == nil)
        {
            cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:CELL_ID2];
            [cell2.contentView setAlpha:0];
            [cell2 setUserInteractionEnabled:NO]; // prevent selection and other stuff
        }
        return cell2;
    }

    [ccTableView setBackgroundColor:[UIColor clearColor]];
    cardsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cardsCell"];

    if(cell == nil){
      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cardsCell" owner:self options:nil];
      cell = [topLevelObjects objectAtIndex:0];
    }

     // Use indexPath.row/2 instead of indexPath.row for the visible section to get the correct datasource index (number of rows is increased to add the invisible rows)
        NSString *nmCard = [[self.cards valueForKeyPath:@"cards.name"] objectAtIndex:(indexPath.row/2)];
        cell.descCardLabel.text = nmCard;

      return cell;
    }



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    // two times minus one (invisible at even rows => visibleCount == invisibleCount+1)
    return [[self.cards valueForKeyPath:@"cards"] count] * 2 - 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row % 2 == 1)
        return 40;
    return 162;
}

 6:滾動TableView,滾動到指定的位置

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
typedef enum {
    UITableViewScrollPositionNone,
    UITableViewScrollPositionTop,
    UITableViewScrollPositionMiddle,
    UITableViewScrollPositionBottom
 } UITableViewScrollPosition;

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 搭建XMPP環境需要幾個輔助工具 1、XAMPP XAMPP(Apache+MySQL+PHP+PERL)是一個功能強大的建 XAMPP 軟體站集成軟體包。 許多人通過他們自己的經驗認識到安裝 Apache 伺服器是件不容易的事兒。如果您想添加 MySQL、PHP 和 Perl,那就更難了。XAMP ...
  • 除了代碼中我們手動加入的 #Waring 標示 所產生的警告,我們都應該重視。下麵是一些警告的處理。 1,方法過期,或 使用新的api 替換方案 multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock ...
  • ...
  • 首先,確保你已經關掉了openfire打開終端 (在應用程式-->實用工具-->)輸入以下命令sudo rm -rf /Library/PreferencePanes/Openfire.prefPanesudo rm -rf /usr/local/openfiresudo rm -rf /Libra ...
  • 很多開發過微信的人估計都遇到過這樣的問題,ios下微信頁面標題更改不了,而安卓卻可以直接用:document.title="你的標題"。 下麵是解決這個問題的hack: 1.jquery方式 2.不依賴jquery ...
  • 項目中有需求是A視圖控制器push之後B視圖控制器需要隱藏底部的tabbar,在pop之後A視圖控制器仍然顯示tabbar. 其實不需要在push操作時敲 self.hidesBottomBarWhenPushed = NO;,然後再pop返回時再設置成NO. 對於這個全局屬性,可以在A中 - (v ...
  • Bundle : http://www.cnblogs.com/BigPolarBear/archive/2012/03/28/2421802.html http://blog.sina.com.cn/s/blog_7b9d64af0101jmj2.html http://www.mamicode. ...
  • 感覺 每走一步都會遇到 問題 都在成長。 今天 申請了 開發者證書 下載下來 之後 安裝 一直顯示此證書的 簽發者無效。 說一下 解決方案 1.先打開鑰匙串 選擇顯示已過期的證書 這是由於蘋果系統的安全證書過期問題導致。 2.在鑰匙串里 選擇 登錄 - 所有項目 3.然後在再搜索框里輸入apple ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...