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;