分类目录归档:ios

core Data-Querying-NSPredicate

Creating an NSFetchRequest!

We’ll consider each of these lines of code one by one ...
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@“Photo”];
request.fetchBatchSize = 20;
request.fetchLimit = 100;
request.sortDescriptors = @[sortDescriptor];
request.predicate = ...;

NSSortDescriptor

NSSortDescriptor *sortDescriptor =
[NSSortDescriptor sortDescriptorWithKey:@“title”
ascending:YES
selector:@selector(localizedStandardCompare:)];

NSPredicate

NSPredicate *predicate =
[NSPredicate predicateWithFormat:@“thumbnailURL contains %@”, serverName];
@“uniqueId = %@”, [flickrInfo objectForKey:@“id”] // unique a photo in the database
@“name contains[c] %@”, (NSString *) // matches name case insensitively!
@“viewed > %@”, (NSDate *) // viewed is a Date attribute in the data mapping!
@“whoTook.name = %@”, (NSString *) // Photo search (by photographer’s name)!
@“any photos.title contains %@”, (NSString *) // Photographer search (not a Photo search)!

NSCompoundPredicate…AND and OR

You can use AND and OR inside a predicate string, e.g. @“(name = %@) OR (title = %@)”!
Or you can combine NSPredicate objects with special NSCompoundPredicates.
NSArray *array = @[predicate1, predicate2];
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:array];

Key Value Coding!

https://developer.apple.com/library/ios/documentation/cocoa/conceptual/KeyValueCoding/Articles/CollectionOperators.html

Can actually do predicates like @“photos.@count > 5” (Photographers with more than 5 photos).! @count is a function (there are others) executed in the database itself.! .!
By the way, all this stuff (and more) works on dictionaries, arrays and sets too ...!
e.g. [propertyListResults valueForKeyPath:@“photos.photo.@avg.latitude”] on Flickr results!
returns the average latitude of all of the photos in the results (yes, really)!
e.g. @“photos.photo.title.length" would return an array of the lengths of the titles of the photos!

Putting it all together!

Let’s say we want to query for all Photographers ...!
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@“Photographer”];
... who have taken a photo in the last 24 hours ...!
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-24*60*60]; !
request.predicate = [NSPredicate predicateWithFormat:@“any photos.uploadDate > %@”, yesterday]; ! ... sorted by the Photographer’s name ...
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@“name” ascending:YES]];

Executing the fetch!

NSManagedObjectContext *context = aDocument.managedObjectContext; !
NSError *error; !
NSArray *photographers = [context executeFetchRequest:request error:&error]; !

Core Data Peristence

//
//  BIDViewController.h
//  Core Data Peristence
//

#import 

@interface BIDViewController : UIViewController

@property (strong, nonatomic) IBOutletCollection(UITextField) NSArray *lineFields;

@end

//
//  BIDViewController.m
//  Core Data Peristence
//

#import "BIDViewController.h"
#import "BIDAppDelegate.h"

static NSString * const kLineEntityName = @"Line";
static NSString * const kLineNumberKey = @"lineNumber";
static NSString * const kLineTextKey = @"lineText";

@interface BIDViewController ()

@end

@implementation BIDViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    BIDAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSFetchRequest *request = [[NSFetchRequest alloc]
                               initWithEntityName:kLineEntityName];
    
    NSError *error;
    NSArray *objects = [context executeFetchRequest:request error:&error];
    if (objects == nil) {
        NSLog(@"There was an error!");
        // Do whatever error handling is appropriate
    }
    
    for (NSManagedObject *oneObject in objects) {
        int lineNum = [[oneObject valueForKey:kLineNumberKey] intValue];
        NSString *lineText = [oneObject valueForKey:kLineTextKey];
        
        UITextField *theField = self.lineFields[lineNum];
        theField.text = lineText;
    }
    
    UIApplication *app = [UIApplication sharedApplication];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(applicationWillResignActive:)
     name:UIApplicationWillResignActiveNotification
     object:app];
}

- (void)applicationWillResignActive:(NSNotification *)notification
{
    BIDAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSError *error;
    for (int i = 0; i < 4; i++) {
        UITextField *theField = self.lineFields[i];
        
        NSFetchRequest *request = [[NSFetchRequest alloc]
                                   initWithEntityName:kLineEntityName];
        
        NSPredicate *pred = [NSPredicate
                             predicateWithFormat:@"(%K = %d)", kLineNumberKey, i];
        [request setPredicate:pred];
        
        NSArray *objects = [context executeFetchRequest:request error:&error];
        if (objects == nil) {
            NSLog(@"There was an error!");
            // Do whatever error handling is appropriate
        }
        
        NSManagedObject *theLine = nil;
        if ([objects count] > 0) {
            theLine = [objects objectAtIndex:0];
        } else {
            theLine = [NSEntityDescription
                       insertNewObjectForEntityForName:kLineEntityName
                       inManagedObjectContext:context];
        }
        
        [theLine setValue:[NSNumber numberWithInt:i] forKey:kLineNumberKey];
        [theLine setValue:theField.text forKey:kLineTextKey];
        
    }
    [appDelegate saveContext];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

TableView-Setion-BIDViewController通讯录:索引,搜索

利用Single View Template 及table view object创建一个通讯录,带有索引,搜索功能
eeeeeeeeeeee4

//
//  BIDViewController.h
//  Sections
//

#import 

@interface BIDViewController : UIViewController
    

@property (copy, nonatomic) NSDictionary *names;
@property (copy, nonatomic) NSArray *keys;

@end

//
//  BIDViewController.m
//  Sections
//

#import "BIDViewController.h"

static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";

@implementation BIDViewController {
    NSMutableArray *filteredNames;
    UISearchDisplayController *searchController;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UITableView *tableView = (id)[self.view viewWithTag:1];
    [tableView registerClass:[UITableViewCell class]
      forCellReuseIdentifier:SectionsTableIdentifier];
    
    filteredNames = [NSMutableArray array];
    UISearchBar *searchBar = [[UISearchBar alloc]
                              initWithFrame:CGRectMake(0, 0, 320, 44)];
    tableView.tableHeaderView = searchBar;
    searchController = [[UISearchDisplayController alloc]
                        initWithSearchBar:searchBar
                        contentsController:self];
    searchController.delegate = self;
    searchController.searchResultsDataSource = self;
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames"
                                                     ofType:@"plist"];
    self.names = [NSDictionary dictionaryWithContentsOfFile:path];
    
    self.keys = [[self.names allKeys] sortedArrayUsingSelector:
                 @selector(compare:)];
}

#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView.tag == 1) {
        return [self.keys count];
    } else {
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 1) {
        NSString *key = self.keys[section];
        NSArray *nameSection = self.names[key];
        return [nameSection count];
    } else {
        return [filteredNames count];
    }
}

- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 1) {
        return self.keys[section];
    } else {
        return nil;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SectionsTableIdentifier];
    if (tableView.tag == 1) {
        NSString *key = self.keys[indexPath.section];
        NSArray *nameSection = self.names[key];
        
        cell.textLabel.text = nameSection[indexPath.row];
    } else {
        cell.textLabel.text = filteredNames[indexPath.row];
    }
    return cell;
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if (tableView.tag == 1) {
        return self.keys;
    } else {
        return nil;
    }
}

#pragma mark - 
#pragma mark Search Display Delegate Methods
- (void)searchDisplayController:(UISearchDisplayController *)controller
  didLoadSearchResultsTableView:(UITableView *)tableView
{
    [tableView registerClass:[UITableViewCell class]
      forCellReuseIdentifier:SectionsTableIdentifier];
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
    [filteredNames removeAllObjects];
    if (searchString.length > 0) {
        NSPredicate *predicate =
        [NSPredicate
         predicateWithBlock:^BOOL(NSString *name, NSDictionary *b) {
            NSRange range = [name rangeOfString:searchString
                                        options:NSCaseInsensitiveSearch];
            return range.location != NSNotFound;
        }];
        for (NSString *key in self.keys) {
            NSArray *matches = [self.names[key]
                                filteredArrayUsingPredicate: predicate];
            [filteredNames addObjectsFromArray:matches];
        }
    }
    return YES;
}

@end

TableView-BIDNameAndColorCell

//  BIDNameAndColorCell.h
//  Cells
//

#import 

@interface BIDNameAndColorCell : UITableViewCell

@property (copy, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *color;

@property (strong, nonatomic) IBOutlet UILabel *nameValue;
@property (strong, nonatomic) IBOutlet UILabel *colorValue;

@end

//
//  BIDNameAndColorCell.m
//  Cells
//

#import "BIDNameAndColorCell.h"

@implementation BIDNameAndColorCell {
    UILabel *_nameValue;
    UILabel *_colorValue;
}

- (id)initWithStyle:(UITableViewCellStyle)style
    reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGRect nameLabelRect = CGRectMake(0, 5, 70, 15);
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
        nameLabel.textAlignment = NSTextAlignmentRight;
        nameLabel.text = @"Name:";
        nameLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview: nameLabel];
        
        CGRect colorLabelRect = CGRectMake(0, 26, 70, 15);
        UILabel *colorLabel = [[UILabel alloc] initWithFrame:colorLabelRect];
        colorLabel.textAlignment = NSTextAlignmentRight;
        colorLabel.text = @"Color:";
        colorLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview: colorLabel];
        
        CGRect nameValueRect = CGRectMake(80, 5, 200, 15);
        _nameValue = [[UILabel alloc] initWithFrame:
                              nameValueRect];
        [self.contentView addSubview:_nameValue];
        
        CGRect colorValueRect = CGRectMake(80, 25, 200, 15);
        _colorValue = [[UILabel alloc] initWithFrame:
                               colorValueRect];
        [self.contentView addSubview:_colorValue];
    }
    return self;
}

- (void)setName:(NSString *)n
{
    if (![n isEqualToString:_name]) {
        _name = [n copy];
        _nameValue.text = _name;
    }
}

- (void)setColor:(NSString *)c
{
    if (![c isEqualToString:_color]) {
        _color = [c copy];
        _colorValue.text = _color;
    }
}

@end

//
//  BIDViewController.h
//  Cells
//

#import 

@interface BIDViewController : UIViewController


@property (copy, nonatomic) NSArray *computers;

@end

//
//  BIDViewController.m
//  Cells
//

#import "BIDViewController.h"
#import "BIDNameAndColorCell.h"

@implementation BIDViewController

static NSString *CellTableIdentifier = @"CellTableIdentifier";

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.computers = @[
    @{@"Name" : @"MacBook", @"Color" : @"White"},
    @{@"Name" : @"MacBook Pro", @"Color" : @"Silver"},
    @{@"Name" : @"iMac", @"Color" : @"Silver"},
    @{@"Name" : @"Mac Mini", @"Color" : @"Silver"},
    @{@"Name" : @"Mac Pro", @"Color" : @"Silver"}];

    UITableView *tableView = (id)[self.view viewWithTag:1];
    tableView.rowHeight = 65;
    UINib *nib = [UINib nibWithNibName:@"BIDNameAndColorCell"
                                bundle:nil];
    [tableView registerNib:nib
    forCellReuseIdentifier:CellTableIdentifier];
}

#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    return [self.computers count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    BIDNameAndColorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    
    NSDictionary *rowData = self.computers[indexPath.row];
    
    cell.name = rowData[@"Name"];
    cell.color = rowData[@"Color"];
    
    return cell;
}

@end

TabBar–Picker-Date-Custom

44445

rrrrrrrr

//  BIDAppDelegate.h
#import 

@interface BIDAppDelegate : UIResponder 

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) IBOutlet UITabBarController *rootController;

@end

#import "BIDAppDelegate.h"

@implementation BIDAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    [[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];
    self.window.rootViewController = self.rootController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end
//  BIDDatePickerViewController.h
//  Pickers
//

#import 

@interface BIDDatePickerViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIDatePicker *datePicker;
- (IBAction)buttonPressed;

@end

#import "BIDDatePickerViewController.h"

@implementation BIDDatePickerViewController

- (IBAction)buttonPressed
{
    NSDate *selected = [self.datePicker date];
    NSString *message = [[NSString alloc] initWithFormat:
                         @"The date and time you selected is: %@", selected];
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Date and Time Selected"
                          message:message
                          delegate:nil
                          cancelButtonTitle:@"Yes, I did."
                          otherButtonTitles:nil];
    [alert show];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSDate *now = [NSDate date];
    [self.datePicker setDate:now animated:NO];
}

@end

//  BIDCustomPickerViewController.h
//  Pickers
//

#import 

@interface BIDCustomPickerViewController : UIViewController


@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@property (strong, nonatomic) IBOutlet UILabel *winLabel;
@property (strong, nonatomic) NSArray *images;
@property (strong, nonatomic) IBOutlet UIButton *button;

- (IBAction)spin;

@end
//
//  BIDCustomPickerViewController.m
//  Pickers
//

#import "BIDCustomPickerViewController.h"
#import 

@implementation BIDCustomPickerViewController {
    SystemSoundID winSoundID;
    SystemSoundID crunchSoundID;
}

-(void)showButton
{
    self.button.hidden = NO;
}

-(void)playWinSound
{
    if (winSoundID == 0) {
        NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"win"
                                                  withExtension:@"wav"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL,
                                         &winSoundID);
    }
    AudioServicesPlaySystemSound(winSoundID);
    self.winLabel.text = @"WINNING!";
    [self performSelector:@selector(showButton)
               withObject:nil
               afterDelay:1.5];
}

- (IBAction)spin
{
    BOOL win = NO;
    int numInRow = 1;
    int lastVal = -1;
    for (int i = 0; i < 5; i++) {
        int newValue = random() % [self.images count];
        
        if (newValue == lastVal) {
            numInRow++;
        } else {
            numInRow = 1;
        }
        
        lastVal = newValue;
        [self.picker selectRow:newValue inComponent:i animated:YES];
        [self.picker reloadComponent:i];
        if (numInRow >= 3) {
            win = YES;
        }
    }
    
    if (crunchSoundID == 0) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"crunch"
                                                         ofType:@"wav"];
        NSURL *soundURL = [NSURL fileURLWithPath:path];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL,
                                         &crunchSoundID);
    }
    AudioServicesPlaySystemSound(crunchSoundID);
    
    if (win) {
        [self performSelector:@selector(playWinSound)
                   withObject:nil
                   afterDelay:.5];
    } else {
        [self performSelector:@selector(showButton)
                   withObject:nil
                   afterDelay:.5];
    }
    self.button.hidden = YES;
    self.winLabel.text = @"";

    if (win) {
        self.winLabel.text = @"WIN!";
    } else {
        self.winLabel.text = @"";
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.images = @[[UIImage imageNamed:@"seven"],
    [UIImage imageNamed:@"bar"], [UIImage imageNamed:@"crown"],
    [UIImage imageNamed:@"cherry"], [UIImage imageNamed:@"lemon"],
    [UIImage imageNamed:@"apple"]];
    
    srandom(time(NULL));
}

#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 5;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    return [self.images count];
}

#pragma mark Picker Delegate Methods
- (UIView *)pickerView:(UIPickerView *)pickerView
            viewForRow:(NSInteger)row
          forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UIImage *image = self.images[row];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    return imageView;
}

@end

The  spin method fires when the user touches the Spin button. In it, we first declare a few variables 
that will help us keep track of whether the user has won. We’ll use  win to keep track of whether 
we’ve found three in a row by setting it to YES if we have. We’ll use  numInRow to keep track of how 
many of the same value we have in a row so far, and we will keep track of the previous component’s 
value in  lastVal so that we have a way to compare the current value to the previous value. We 
initialize  lastVal to −1 because we know that value won’t match any of the real values.
BOOL win = NO;
int numInRow = 1;
int lastVal = −1;

Next, we loop through all five components and set each one to a new, randomly generated row 
selection. We get the count from the column1 array to do that, which is a shortcut we can use 
because we know that all five columns have the same number of values.
for (int i = 0; i < 5; i++) {
    int newValue = random() % [self.images count];
We compare the new value to the previous value and increment numInRow if it matches. If the value 
didn’t match, we reset numInRow back to  1. We then assign the new value to lastVal so we’ll have it 
to compare the next time through the loop.
if (newValue == lastVal) {
    numInRow++;
} else {
    numInRow = 1;
}
lastVal = newValue;
After that, we set the corresponding component to the new value, telling it to animate the change, 
and we tell the picker to reload that component.
[self.picker selectRow:newValue inComponent:i animated:YES];
[self.picker reloadComponent:i];
 
214 CHAPTER 7: Tab Bars and Pickers
The last thing we do each time through the loop is check whether we have three in a row, and set 
win to  YES if we do.
if (numInRow >= 3) {
    win = YES;
}
Once we’re finished with the loop, we set the label to say whether the spin was a win.
if (win) {
    self.winLabel.text = @"WIN!";
} else {
    self.winLabel.text = @"";
}
The viewDidLoad Method
The first thing we do is load six different images. We do this using a convenience method on the 
UIImage class called  imageNamed:.
self.images = @[[UIImage imageNamed:@"seven"],
[UIImage imageNamed:@"bar"], [UIImage imageNamed:@"crown"],
[UIImage imageNamed:@"cherry"], [UIImage imageNamed:@"lemon"],
[UIImage imageNamed:@"apple"]];
The last thing we do in this method is to seed the random number generator. If we don’t do that, the 
game will play the same way every time, which gets kind of boring.
srandom(time(NULL));

SwitchView:在不同的ViewController插入VIewController

例如三个Controller,rootController,blueController,yellowController

在rootcontorller插入blueController

1.定义并获取yellowController
2.插入[self.view insertSubview:self.yellowController.view atIndex:0]

    _switchViewController =[[SwitchViewController alloc] initWithNibName:@"SwitchViewController" bundle:nil];
    
    [self.window setRootViewController:_switchViewController];
    self.window.rootViewController = self.switchViewController;
#import 
#import "SwitchViewController.h"

@class SwitchViewController;

@interface SwitchViewAppDelegate : UIResponder 

@property (nonatomic, strong) SwitchViewController *switchViewController;

@property (strong, nonatomic) UIWindow *window;

@end
  _switchViewController =[[SwitchViewController alloc] initWithNibName:@"SwitchViewController" bundle:nil];
    
    [self.window setRootViewController:_switchViewController];
    
    // Override point for customization after application launch.
#import 
#import "BlueViewController.h"
#import "YellowViewController.h"

@interface SwitchViewController : UIViewController

@property (nonatomic, strong) BlueViewController *blueController;
@property (nonatomic, strong) YellowViewController *yellowController;

- (IBAction)switchView:(id)sender;
@end

#import "SwitchViewController.h"

@interface SwitchViewController ()

@end

@implementation SwitchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViewController" bundle:nil];
    [self.view insertSubview:self.yellowController.view atIndex:0];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if (self.yellowController.view.superview == nil) {
        self.yellowController.view = nil;
    }else{
        self.blueController.view = nil;
    }
}

- (IBAction)switchView:(id)sender {
    
    [UIView beginAnimations:@"Begin Flig" context:nil];
    [UIView setAnimationDuration:1.2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if (self.blueController.view.superview == nil) {
        if (self.blueController == nil) {
            self.blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];
            
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES ];
            [self.yellowController.view removeFromSuperview];
            [self.view insertSubview:self.blueController.view atIndex:0];
        }
    }
    else{
            self.yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViewController" bundle:nil];
        
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES ];
            [self.blueController.view removeFromSuperview];
            [self.view insertSubview:self.yellowController.view atIndex:0];
    }[UIView commitAnimations];
    }

@end

kkkkkkkkkku