Advertisement
Guest User

Untitled

a guest
May 8th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ViewController.h
  2.  
  3.     #import <UIKit/UIKit.h>
  4.     #import "DataController.h"
  5.  
  6.     @interface ViewController : UIViewController <UITableViewDelegate>
  7.     {
  8.         IBOutlet UITableView* view;
  9.         IBOutlet UIButton* editButton;
  10.    
  11.         DataController* dataController;
  12.         Boolean isEditing;
  13.      }
  14.  
  15.     -(IBAction)toggleEdit:(id)sender;
  16.  
  17.     @end
  18.  
  19. #ViewController.m
  20.  
  21.     #import "ViewController.h"
  22.     #import "DataController.h"
  23.     #import "ShipCell.h"
  24.     #import "DetailViewController.h"
  25.  
  26.     @interface ViewController ()
  27.  
  28.     @end
  29.  
  30.     @implementation ViewController
  31.  
  32.     - (void)viewDidLoad
  33.     {
  34.         [super viewDidLoad];
  35.     // Do any additional setup after loading the view, typically from a nib.
  36.         dataController = [DataController getInstance];
  37.         isEditing = false;
  38.    
  39.         [view setEditing:YES];
  40.     }
  41.  
  42.     - (void)didReceiveMemoryWarning
  43.     {
  44.         [super didReceiveMemoryWarning];
  45.         // Dispose of any resources that can be recreated.
  46.     }
  47.  
  48.     -(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
  49.     {
  50.         return [dataController getDataCount];
  51.     }
  52.  
  53.      -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  54.     {
  55.         static NSString* cellID = @"Cell";
  56.    
  57.         ShipCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  58.    
  59.         if (!cell)
  60.         {
  61.             NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"ShipCellView" owner:self options:nil];
  62.             cell = [views objectAtIndex:0];
  63.         }
  64.    
  65.    
  66.         cell.nameLabel.text = [dataController getNameAtIndex:indexPath.row];
  67.         cell.operatorLabel.text = [dataController getOperatorAtIndex:indexPath.row];
  68.         cell.flagImage.image = [dataController getFlagAtIndex:indexPath.row];
  69.  
  70.         return cell;
  71.     }
  72.  
  73.     -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  74.     {
  75.         dataController.selectedIndex = indexPath.row;
  76.    
  77.         DetailViewController *detailVC = [[DetailViewController alloc ] initWithNibName:@"ShipDetailView" bundle:nil];
  78.    
  79.         [UIView transitionWithView:self.view.superview duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{[self presentViewController:detailVC animated:false completion:nil];} completion:nil];
  80.    
  81.     }
  82.  
  83.     -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  84.     {
  85.         return UITableViewCellEditingStyleDelete;
  86.     }
  87.  
  88.     - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  89.     return YES;
  90.     }
  91.  
  92.     -(IBAction)toggleEdit:(id)sender
  93.     {
  94.  
  95.         if(isEditing)
  96.         {
  97.             NSLog(@"true");
  98.             isEditing = false;
  99.             [view setEditing:false];
  100.         }
  101.         else
  102.         {
  103.             NSLog(@"false");
  104.             isEditing = true;
  105.             [view setEditing:true];
  106.         }
  107.    
  108.     }
  109.  
  110.     -(void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated];
  111.         [view setEditing:editing animated:YES]; }
  112.  
  113.     @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement