Basic knowledge of IOS development-fragment 40, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 40, basic knowledge of ios-Fragment

1: Quick Error Reporting tips for 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);}];

Note: MASAttachKeys displays a clear error message;

 

2: Jump to system settings for iOS

Note: To enable the function of redirecting from the application to the system settings page, you must first add prefs to Targets-Info-URL Types-URL Schemes.

Jump to WIFI settings if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "prefs: root = WIFI"]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "prefs: root = WIFI"];} jump to Bluetooth if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "prefs: root = Bluetooth"]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "prefs: root = Bluetooth"];} jump to General if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "prefs: root = General"]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "prefs: root = General"];} jump to the local if ([[UIApplication sharedApplication] canOpenURL: [NSURLURLWithString: @ "prefs: root = General & path = About"]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "prefs: root = General & path = About"];} jump to the target service if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "prefs: root = LOCATION_SERVICES "]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @" prefs: root = LOCATION_SERVICES "];} jump to notification if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "prefs: root = icationications_id"]) {[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "prefs: root = icationications_id"];}

3: The UITableView section scrolls with the cell.

Implement the following method of UITableView: # pragma mark-Scroll-(void) scrollViewDidScroll :( UIScrollView *) scrollView {CGFloat sectionHeaderHeight = 40; // fixed section scrolling with 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: How does TableView refresh a specified cell or section?

// Refresh NSIndexSet * indexSet = [[NSIndexSet alloc] initWithIndex: 2] for a section; [tableview reloadSections: indexSet withRowAnimation: UITableViewRowAnimationAutomatic]; // refresh NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 3 inSection: 0]; [tableView reloadRowsAtIndexPaths: [NSArray arrayWithObjects: indexPath, nil] withRowAnimation: parent];

5: TableView another method to implement the effect of blank rows

Increase the total number of items, and then calculate the remainder

- (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: Scroll TableView to the specified position

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.