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
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...