IOS開發基礎知識--片段40,ios基礎知識--片段

來源:互聯網
上載者:User

IOS開發基礎知識--片段40,ios基礎知識--片段

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;

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.