Skip to main content

Posts

Showing posts from November, 2014

#iOS8 #XCode6 #SizeClasses

       In Xcode 6, new feature called "Size classes" have been introduced. The size classes are used for making the storyboard compatible for all iOS Devices(iPhone & iPad, even iPod) in both portrait as well as Landscape orientations. To set the size class: 1) Choose "Universal" option while creating the project. 2) Check the auto layout checkbox in Main.storyboard -> File Inspector -> "Use Auto Layout" 3) Check the size classes check box in Main.storyboard -> File Inspector -> "Use Size Classes". There are two types of size classes: Regular and Compact. Hence the different configurations(screen sizes) include, 1) wAny hAny - Base configuration 2) wCompact hRegular - iPhone Portrait 3) wCompact hCompact - iPhone Landscape 4) wRegular wAny - iPad Landscape and portrait On selecting the base configuration, the storyboard works the same in all devices. This can be viewed in "preview" option in the assis

Collection View - 2D Display

/*Nothing but dividing items into number of columns and rows */ sizeForItemAtIndexPath() It returns the size for each item. In collection view, each cell is considered as item and not as rows or columns. To make it 2D(columns and rows), distribute the collection view frame size into several item sizes, in such a way that x number of items can be placed in a single row. For instance, if there are 50 items( 5 items in each row which is nothing but 5 columns in 1 row and there are 10 such rows).   Given collection view frame size is 1000. Now this can be done by dividing the frame size by number of columns,   i.e., 1000/5 = 200. So each items width will be 200.

Container View - Multiple View Controllers

       By default, Each Container View can have one child view controller only. Only one controller can be added to container using "Embed segue".       In order to add multiple view controller,  the following may help:      Use a separate container view controller and add it using embed segue to the container view. Now from the container view controller that is created, perform transition to different child view controllers using custom segues.

Separator Inset Problem - iOS 8

                    In iOS8, there is extra space in table view separators by default. It is nothing but the edge inset. To remove the separator edge inset, in iOS 7, custom separator insets can be set in the attributes inspector of the table view. In iOS 8, use the following in the table view controller: //set edge inset zero for default separator -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath     {     if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {     [self. tableView setSeparatorInset:UIEdgeInsetsZero];   }     if ([self. tableView respondsToSelector:@selector(setLayoutMargins:)]) {     [self. tableView setLayoutMargins:UIEdgeInsetsZero];   }     if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {     [cell setLayoutMargins:UIEdgeInsetsZero];   } }

Table View - Extra Rows

To remove the default extra rows in the table view, use the below code in table view controller: tableView.edgesForExtendedLayout = UIRectEdgeNone; tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

Running Database Fetch (Core Data) in Background Thread using magical Record

   To run database fetching in background thread(in a separate context), so that the UI does not get blocked: __block NSMutableArray *dataArray= [[NSMutableArray alloc] init];   // Create a child context of the main context   NSManagedObjectContext *privateContext = [NSManagedObjectContext MR_context];   // When using private contexts execute the core data code in it's private queue using performBlock: or performBlockAndWait:   [privateContext performBlock:^{     // Execute fetch   NSArray *privateObjects;   if(entity_predicate == nil) {       //fetch all! duh!       privateObjects = [self MR_findAllSortedBy:sort_key ascending:YES inContext:privateContext];     } else {       privateObjects = [self MR_findAllSortedBy:sort_key ascending:YES withPredicate:entity_predicate inContext:privateContext];     }         // Convert fetched objects into object IDs which can be pulled out of the main context     NSArray *privateObjectIDs = [privateObjects