CGContextSetLineDash虚线

333

    float lengths[] = {10,5};  
    CGContextSetLineDash(context, 0, lengths, 2);    
    CGContextMoveToPoint(context, 0.0, 20.0);    
    CGContextAddLineToPoint(context, 310.0, 20.0);     
    CGContextStrokePath(context);  
                              
    CGContextSetLineDash(context, 5, lengths, 2);  
    CGContextMoveToPoint(context, 0.0, 40.0);    
    CGContextAddLineToPoint(context, 310.0, 40.0);  
    CGContextStrokePath(context);             
                                                  
    CGContextSetLineDash(context, 8, lengths, 2);     
    CGContextMoveToPoint(context, 0.0, 60.0);             
    CGContextAddLineToPoint(context, 310.0, 60.);             
    CGContextStrokePath(context);   

CGContextAddCurveToPoint曲线弧线详解

CGContextAddCurveToPoint

 

3333333333333
curve3

CGContextAddQuadCurveToPoint

 

 

-(void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2);

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

    CGContextMoveToPoint(context, 100, 100);
    CGContextAddArcToPoint(context, 100, 200, 200, 200, 100);
    CGContextAddCurveToPoint(context, 50, 260, 280, 350, 200, 400);
    CGContextMoveToPoint(context, 200, 100);
    CGContextAddQuadCurveToPoint(context, 400, 150, 200, 300);
    CGContextStrokePath(context);

}

2D Graphics With Quartz: Drawing画线两实例(画线的几个步骤)

画线的几个步骤:
1.设置线宽: CGContextSetLineWidth
2.设置线颜色
3.设置线的起点:CGContextMoreToPoint
4。线的终点:CGcontextAddLineToPoint
5.生成线:CGContextStrokePath;

实例一,
利用CGColorSpaceRef获取到colorspace;
利用CGPoint componnents[] = {};

Components with colorspace consist of CGColorref color –CGColorCreate(colorSpace, components);

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 5.0);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
    CGColorRef color = CGColorCreate(colorSpace, components);
    CGContextSetStrokeColorWithColor(context, color);
    CGContextMoveToPoint(context, 0, 0 );
    CGContextAddLineToPoint(context, 350, 350);
    CGContextStrokePath(context);

    
    CGColorSpaceRelease(colorSpace);
    CGColorRelease(color);
    }

方法二,直接用UIColor获取线的颜色:

 - (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 5.0);
   // CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//    CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
  //  CGColorRef color = CGColorCreate(colorSpace, components);

    
    UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:0.8f alpha:1.0];

    CGContextSetStrokeColorWithColor(context, color.CGColor);
    CGContextMoveToPoint(context, 0, 0 );
    CGContextAddLineToPoint(context, 350, 350);
    CGContextStrokePath(context);

    
  //  CGColorSpaceRelease(colorSpace);
   // CGColorRelease(color.CGColor);

画线的几个步骤:
1.设置线宽: CGContextSetLineWidth
2.设置线颜色
3.设置线的起点:CGContextMoreToPoint
4。线的终点:CGcontextAddLineToPoint
5.生成线:CGContextStrokePath;

- (void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext()    ;

    
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

    
    CGRect rectangle = CGRectMake(100, 100, 200, 80);

    
    CGContextStrokeRect(context, rectangle);
}

-(void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2);

    
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGRect ellipse = CGRectMake(100, 100, 150, 80);

    

    
    CGContextAddEllipseInRect(context, ellipse);
    CGContextStrokePath(context);

    
}


CollectionView应用篇-Database-delegate

1.numberOfSectionsInCollectionView
2.numberOfItensInSection;
3.cellForItemAtIndexPath;
4.sizeForItemAtIndexPath;
5.didSeclectItemAtIndexPath;

//
//  MyCollectionViewController.m
//  CollectionDemo
//
//  Created by xushao on 
//  Copyright (c)  年 xushao. All rights reserved.
//

#import "MyCollectionViewController.h"

@interface MyCollectionViewController ()

@end

@implementation MyCollectionViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _carImages = [@[@"chevy_small.jpg",@"ford_small.jpg",
    @"highlander_small.jpg",@"honda_small.jpg",@"jeep_small.jpg",@"mini_small.jpg",@"nissan_small.jpg",@"rover_small.jpg",@"smart_small.jpg",@"venza_small.jpg",@"volvo_small.jpg",@"wv_small.jpg" ] mutableCopy];

    
	// Do any additional setup after loading the view.
}

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

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _carImages.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    int row = [indexPath row];
    myCell.imageView.image = [UIImage imageNamed:_carImages[row]];
    return myCell;
}


-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    int row = [indexPath row];
    UIImage *image = [UIImage imageNamed:_carImages[row]];
    return image.size;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewFlowLayout *myLayout = [[UICollectionViewFlowLayout alloc] init];
    
    myLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    [self.collectionView setCollectionViewLayout:myLayout animated:YES];
}



-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    MySuplementaryView *header;
    if ([kind isEqual:UICollectionElementKindSectionHeader]) {
    header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeadView" forIndexPath:indexPath];
        header.headLabel.text = @"Car Images" ;
        
    }
    return header;

}




@end

CoreData实验

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    _viewController = [[coreDataViewController alloc] initWithNibName:@"coreDataViewController" bundle:nil];
    
    [self.window setRootViewController:_viewController];
        // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
//
//  coreDataViewController.m
//  coreData
//
//  Created by xushao .
//  Copyright (c)年 xushao. All rights reserved.
//

#import "coreDataViewController.h"

@interface coreDataViewController ()

@end

@implementation coreDataViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

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

- (IBAction)saveData:(id)sender {
    coreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    
    NSManagedObject *newContacts = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context];
    
    [newContacts setValue:_name.text forKey:@"name" ];
    [newContacts setValue:_address.text forKey:@"address"];
    [newContacts setValue:_phone.text forKey:@"phone"];
    NSError *error;
    [context save:&error];
    _status.text = @"Data Save";
    
    _name.text = @"";
    _address.text = @"";
    _phone.text = @"";
    
}

- (IBAction)findData:(id)sender {
    coreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    
    NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Contacts" inManagedObjectContext:context];
    
    NSFetchRequest *reques = [[NSFetchRequest alloc] init];
    [reques setEntity:entityDesc];
    
    NSPredicate *predic = [NSPredicate predicateWithFormat:@"name = %@", _name.text];
    
    [reques setPredicate:predic ];
    
    NSManagedObject *mathes = nil;
    NSError *error;
    NSArray *objects = [context executeFetchRequest:reques error:&error];
    
    if ([objects count] ==0) {
        _status.text =@"No Mathes";
    }else{
        mathes = objects[0];
        _address.text = [mathes valueForKey:@"address"];
        _phone.text = [mathes valueForKey:@"phone"];
        _status.text =[NSString stringWithFormat:@"%d mathes Found", [objects count]];
    }
    
}

- (IBAction)backgroundTouched:(id)sender {
    [_name resignFirstResponder];
    [_address resignFirstResponder];
    [_phone resignFirstResponder];
}
@end

NSFileManager-NSData-IOS6文件管理,数据读写-Resignfirstresponder

要点:
NSFileManager获取到的数据类型为NSData,用initWithData转为NSString
NSString数据转成Data数据:
NSString *saveText = _inputText.text;
NSData *saveData = [saveText dataUsingEncoding:NSASCIIStringEncoding ];

//在指定目录创建文档,读取数据contentsAtPath:path,写入数据createFileAtPath;
//  fileExample2ViewController.h
//  fileExample2
//
//  Created by Xu Shao 
//  Copyright (c) Xu Shao All rights reserved.
//

#import 

@interface fileExample2ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *inputText;
- (IBAction)buttonSave:(UIButton *)sender;

- (IBAction)pressEnter:(UITextField *)sender;

-(IBAction)backgroundTouched:(id)sender;
@end
//
//  fileExample2ViewController.m
//  fileExample2
//
//  Created by Xu Shao
//  Copyright (c) Xu Shao qun. All rights reserved.
//

#import "fileExample2ViewController.h"

@interface fileExample2ViewController ()

@end

@implementation fileExample2ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    NSFileManager *fileMgr =[NSFileManager defaultManager];

    
    NSString *path = @"/Users/iamshall/Documents/mytest2.txt";

    
    if ([fileMgr fileExistsAtPath:path]) {
        NSData *dataText =[fileMgr contentsAtPath:path];

        
        NSString *dataString = [[NSString  alloc] initWithData:dataText encoding:NSASCIIStringEncoding];

        
        _inputText.text = dataString;
    }
// Do any additional setup after loading the view, typically from a nib.
}

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



- (IBAction)buttonSave:(UIButton *)sender {
    NSString *saveText = _inputText.text;
    NSData *saveData = [saveText dataUsingEncoding:NSASCIIStringEncoding   ];
    NSFileManager *fileMgr = [NSFileManager defaultManager];

    
    [fileMgr createFileAtPath:@"/Users/iamshall/Documents/mytest2.txt" contents:saveData attributes:nil];

    
}

- (IBAction)pressEnter:(UITextField *)sender {
    [sender resignFirstResponder];
}

-(IBAction)backgroundTouched:(id)sender{
    [_inputText resignFirstResponder];
}

@end

//  在当前工作目录下创建文档,写入数据,读取数据
//  fileExample2ViewController.m
//  fileExample2
//
//  Created by Xu Shao qun on 1/24/13.
//  Copyright (c) 2013 Xu Shao qun. All rights reserved.
//

#import "fileExample2ViewController.h"

@interface fileExample2ViewController ()

@end

@implementation fileExample2ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    NSFileManager *fileMgr =[NSFileManager defaultManager];
    NSArray *pathDic = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    
    NSString *dirPath = pathDic[0];

    
    NSString *filePath = [dirPath stringByAppendingPathComponent:@"test.txt"];

    

    
    if ([fileMgr fileExistsAtPath:filePath]) {
        NSData *dataText =[fileMgr contentsAtPath:filePath];

        
        NSString *dataString = [[NSString  alloc] initWithData:dataText encoding:NSASCIIStringEncoding];

        
        _inputText.text = dataString;
    }
// Do any additional setup after loading the view, typically from a nib.
}

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



- (IBAction)buttonSave:(UIButton *)sender {
    NSArray *dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSFileManager *fileMgr = [NSFileManager defaultManager];

    NSString *docsDir = dirPath[0];

    
    NSString *filePath = [docsDir stringByAppendingPathComponent:@"test.txt"];

    
    NSString *saveText = _inputText.text;
    NSData *saveData = [saveText dataUsingEncoding:NSASCIIStringEncoding   ];

    
    [fileMgr createFileAtPath:filePath contents:saveData attributes:nil];

    
}

- (IBAction)pressEnter:(UITextField *)sender {
    [sender resignFirstResponder];
}

-(IBAction)backgroundTouched:(id)sender{
    [_inputText resignFirstResponder];
}

IOS6开发-PickerViewController

PickerViewController的一个例子,一个文本输入,一个label,还有一个picker包括国家名称,汇率换算;

//
//  PickerViewController.h
//  Picker
//
//  Copyright (c)  xushao. All rights reserved.
//

#import 

@interface PickerViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *dollarText;
- (IBAction)enterText:(UITextField *)sender;

@property (strong, nonatomic) IBOutlet UITextField *resultLabel;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;


@property (nonatomic, strong) NSArray *countryNames;
@property (nonatomic, strong) NSArray *exchangeRates;
@end





//
//  PickerViewController.m
//  Picker
//
//  Copyright (c) 年 xushao. All rights reserved.
//

#import "PickerViewController.h"

@interface PickerViewController ()

@end

@implementation PickerViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _countryNames = @[@"China Yuan(CNY)", @"Australia(AUS) "];
    
    _exchangeRates = @[@6.5f, @2.2f];
    
	// Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)enterText:(UITextField *)sender {
    [sender resignFirstResponder];
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return _countryNames.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return _countryNames[row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    float dollarfolat = [_dollarText.text floatValue];
    float rate = [_exchangeRates[row] floatValue];
    
    float result = dollarfolat * rate ;
    
    NSString *resultString = [NSString stringWithFormat:@"%.2f USD = %.2f %@", dollarfolat, result, _countryNames[row]]  ;
    
    _resultLabel.text = resultString;
}



@end

NSDatePicker:NSDate-NSLocale-initWithLocaleIdentifier-descriptionWithLocale

#import 

@interface DataPickerViewController : UIViewController

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


@property (strong, nonatomic) IBOutlet UILabel *dateLabel;

- (IBAction)getSelected:(UIButton *)sender;
@end
- (IBAction)getSelected:(UIButton *)sender {
    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    NSDate *theDate = [_datePicker date];
    NSString *dateString =[[NSString alloc] initWithFormat:@"%@",[theDate descriptionWithLocale:usLocale] ];
    _dateLabel.text = dateString;
}

TableViewController_ViewController_Segue_UITableViewCell

Keyrods:

prepareForSegue–[segue identifier]–[segue destinationController]–[self.TableView indexPathForSelectedRow]-int row = [indexPath row]

要点:

1.TableViewController包括:TableView-TableViewCell-Label Object, ImageView

a.cell.makeLabel.text
b.cell.carImage.image = [UIimage imageWithNamed:…]

获取用户选择的行:
NSIndexPath *tablePath = [self.TableView indexPathForSelectedRow]
int row = [tablePah row]

**PrepareForSegue
a.[[segue identifier] isEqualToString…]
b.carDetailsViewController *destinationController = [segue destinationViewController]

Create outlets at the Table View Cell.
Create NSArray to store data sources.
Init the array and assigne the data of array to outlets.(需要指定具体cell及行数)

segue

创建一个view controller, 创建view controller对应的outlets,设置outlet的property
命名segue
在主controller配置prepareforsegue

用到的参数:
[segue identifier]
[segue destinationViewController]
NSIndexPath [self.TableView indexPathForSelectedRow]
[indexPath row]

//
//  CarTableViewCell.h
//  CarTableView
//
//  Created by Xu Shao on.
//  Copyright (c) 2013 Xu Shao. All rights reserved.
//

#import 

@interface CarTableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *makeLabel;
@property (strong, nonatomic) IBOutlet UIImageView *carImage;

@end



//
//  CarTableViewCell.m
//  CarTableView
//
//  Created by Xu Shao on.
//  Copyright (c) 2013 Xu Shao. All rights reserved.
//

#import "CarTableViewCell.h"

@implementation CarTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end






//
//  CarTableViewController.h
//  CarTableView
//
//  Created by Xu Shao on.
//  Copyright (c) 2013 Xu Shao. All rights reserved.
//

#import 

@interface CarTableViewController : UITableViewController
@property (nonatomic, strong) NSArray *carMakes;
@property (nonatomic, strong) NSArray *carImages;

@end



//
//  CarTableViewController.m
//  CarTableView
//
//  Created by Xu Shao on.
//  Copyright (c) 2013 Xu Shao. All rights reserved.
//

#import "CarTableViewController.h"
#import "CarTableViewCell.h"
#import "CarDetailsViewController.h"

@interface CarTableViewController ()

@end

@implementation CarTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    _carMakes = @[@"BMW",@"Auto"];
    _carImages =[UIImage imageWithName:@..]

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return _carMakes.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"carTableCell";
    CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    
    // Configure the cell...

    
    int row = [indexPath row];

    
    cell.makeLabel.text = _carMakes[row];
    cell.carImage.image = [UIImage imageNamed:_carImages[row] ];

    
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"carDetailssegue"]) {
        CarDetailsViewController *mydestinationController = [segue destinationViewController];
        NSIndexPath *mypath = [self.tableView indexPathForSelectedRow];
        int row = [mypath row];
        mydestinationController.myCarDetails = @[_carMakes[row],_carImages[row]  ];

        
    }

    
}

@end



//
//  CarDetailsViewController.h
//  CarTableView
//
//  Created by Xu Shao on.
//  Copyright (c) 2013 Xu Shao. All rights reserved.
//

#import 

@interface CarDetailsViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel *myCarMake;

@property (strong, nonatomic) IBOutlet UIImageView *myCarImage;

@property (nonatomic, strong) NSArray *myCarDetails;

@end

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    _myCarMake.text = _myCarDetails[0];

    
    _myCarImage.image = [UIImage imageNamed:_myCarDetails[1]];

    
// Do any additional setup after loading the view.
}

移除constraint

3

2222222


@interface XUViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *myTextField;

@property (strong, nonatomic) IBOutlet UIButton *mybutton;

@property (strong, nonatomic) IBOutlet UIView *viewB;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *centerContraint;

@end
#import "XUViewController.h"

@interface XUViewController ()

@end


@implementation XUViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib
    [self.viewB removeConstraint:_centerContraint];
    [_mybutton setTranslatesAutoresizingMaskIntoConstraints:NO];

    NSLayoutConstraint *myConstraint = [NSLayoutConstraint constraintWithItem:_myTextField attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_mybutton attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];

    [self.view addConstraint:myConstraint];

}

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

@end