Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ViewController.h
- #import <UIKit/UIKit.h>
- #import "DataController.h"
- @interface ViewController : UIViewController <UITableViewDelegate>
- {
- IBOutlet UITableView* view;
- IBOutlet UIButton* editButton;
- DataController* dataController;
- Boolean isEditing;
- }
- -(IBAction)toggleEdit:(id)sender;
- @end
- #ViewController.m
- #import "ViewController.h"
- #import "DataController.h"
- #import "ShipCell.h"
- #import "DetailViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- dataController = [DataController getInstance];
- isEditing = false;
- [view setEditing:YES];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [dataController getDataCount];
- }
- -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString* cellID = @"Cell";
- ShipCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell)
- {
- NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"ShipCellView" owner:self options:nil];
- cell = [views objectAtIndex:0];
- }
- cell.nameLabel.text = [dataController getNameAtIndex:indexPath.row];
- cell.operatorLabel.text = [dataController getOperatorAtIndex:indexPath.row];
- cell.flagImage.image = [dataController getFlagAtIndex:indexPath.row];
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- dataController.selectedIndex = indexPath.row;
- DetailViewController *detailVC = [[DetailViewController alloc ] initWithNibName:@"ShipDetailView" bundle:nil];
- [UIView transitionWithView:self.view.superview duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{[self presentViewController:detailVC animated:false completion:nil];} completion:nil];
- }
- -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return UITableViewCellEditingStyleDelete;
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- -(IBAction)toggleEdit:(id)sender
- {
- if(isEditing)
- {
- NSLog(@"true");
- isEditing = false;
- [view setEditing:false];
- }
- else
- {
- NSLog(@"false");
- isEditing = true;
- [view setEditing:true];
- }
- }
- -(void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated];
- [view setEditing:editing animated:YES]; }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement