1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
//
// MasterViewController.m
// projetTableView
//
// Created by ket on 08/03/2015.
// Copyright (c) 2015 ket. All rights reserved.
//
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "Tache.h"
@interface MasterViewController ()
@property NSMutableArray *objects;
@end
@implementation MasterViewController
@synthesize objects;
- (void)awakeFromNib {
[super awakeFromNib];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.preferredContentSize = CGSizeMake(320.0, 600.0);
//self.title = NSLocalizedString(@"Master",@"Taches");
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.navigationItem.title = @"Tâches"; // titre
// ----- Création des sous tableaux
for(int i=0;i<4;i++){
NSMutableArray * section = [[NSMutableArray alloc]init];
[objects addObject:section];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// =============== Inserer une Tache ===============
- (void)insertNewObject:(id)sender {
/*
if (!self.objects) {
self.objects = [[NSMutableArray alloc] init];
}
*/
Tache* uneTache = [[Tache alloc] initWithTitre:@"A faire" Andpriorite:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.objects insertObject:uneTache atIndex:0];
}
#pragma mark - Segues
// =============== Detail d'une tache ===============
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Tache * object = self.objects[indexPath.row];
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
NSString * t = [object titre];
int p = [object priorite];
NSString * detail = [[NSString alloc] initWithFormat:@"%@ (priorité: %d)",t,p];
[controller setDetailItem:detail];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.objects.count;
}
// =============== Tâches ===============
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
Tache * object = self.objects[indexPath.row];
NSString * affTache = [[NSString alloc] initWithFormat:@"%@ priorité: %d",[object titre],[object priorite]];
cell.textLabel.text = affTache;
// ---------- images des priorités ----------
/*
UIImageView* image = cell.imageView ;
NSString* uneImage = [NSString stringWithFormat:@"/images/prio%d.png",[self.objects[indexPath.row]priorite]];
[image setImage:[UIImage imageNamed:uneImage]];
*/
/*
UIImage * image = [UIImage imageNamed:@"/images/prio1.png"] ;
cell.imageView.image = image ;
*/
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.objects removeObjectAtIndex:indexPath.row];
[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.
}
}
-(NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section
{
switch (section) {
case 0:
return @"Divers";
case 1:
return @"Personnel";
case 2:
return @"Professionnel";
default:
return @"Défaut";
}
}
/*
-(void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * message = [[NSString alloc] initWithFormat:@"Bonjour, %ld",(long)indexPath.row];
self.detailViewController.detailItem = message ;
}
*/
@end |
Partager