Showing posts with label IPhone. Show all posts
Showing posts with label IPhone. Show all posts
0 comments

Xcode how to sort array Object

NSMutableArray *array = [[NSMutableArray alloc] init];
        [array addObject:[[Student alloc] initWithID:1 withName:@"Chi kheang"]];
        [array addObject:[[Student alloc] initWithID:3 withName:@"Rabee"]];
        [array addObject:[[Student alloc] initWithID:2 withName:@"Sothearoth"]];
        [array addObject:[[Student alloc] initWithID:4 withName:@"Bebe"]];
        [array addObject:[[Student alloc] initWithID:5 withName:@"Lyhour"]];
        
        //sort the object
        NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
        [array sortUsingDescriptors:[NSArray arrayWithObject:sort]];
        
        //print log
        for (Student *s in array) {
            NSLog(@"Student ID = %i and Name = %@\n",s.studentID,s.name);
        }


This is the out put log
0 comments

Xcode how to set tapGuesture on UIImage

in your viewDidLoad method
CGRect frame = CGRectMake(0, 50, 320, 200);
    
    //create the object for the imageview
    imageView = [[UIImageView alloc] initWithFrame:frame];
    imageView.image = [UIImage imageNamed:@"p5.png"];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    imageView.userInteractionEnabled = YES;
    imageView.multipleTouchEnabled = YES;
    
    [self.view addSubview:imageView];
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    //tap gesture
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] 
                                          initWithTarget:self 
                                          action:@selector(handleTapGesture:)];
    tapGesture.numberOfTapsRequired = 2;
    [imageView addGestureRecognizer:tapGesture];
    [tapGesture release];

implement handleTapGesture method when you tap on image.
-(IBAction)handleTapGesture:(UIGestureRecognizer *)sender {
    if (sender.view.contentMode == UIViewContentModeScaleAspectFit)
        sender.view.contentMode = UIViewContentModeCenter;
    else
        sender.view.contentMode = UIViewContentModeScaleAspectFit;
}

this is your p5.png image

You can download the Example here