Bonjour,
J'ai crée une master-detail application. J'ai rajouté 4 sections, j'ai donc mis dans le tableau objects 4 sous-tableaux. Quand j'ajoute un objet, j’obtiens cette erreur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
2015-03-12 19:07:14.426 Tâches[365:3861] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.69/UITableView.m:1377
2015-03-12 19:07:14.464 Tâches[365:3861] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001075b6b75 __exceptionPreprocess + 165
	1   libobjc.A.dylib                     0x000000010724fbb7 objc_exception_throw + 45
	2   CoreFoundation                      0x00000001075b69da +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x0000000106e6c4cf -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   UIKit                               0x0000000107a796ee -[UITableView _endCellAnimationsWithContext:] + 5574
	5   TaÃÇches                            0x0000000106d1e831 -[MasterViewController insertNewObject:] + 305
	6   UIKit                               0x00000001079a7582 -[UIApplication sendAction:to:from:forEvent:] + 75
	7   UIKit                               0x00000001079a7582 -[UIApplication sendAction:to:from:forEvent:] + 75
	8   UIKit                               0x0000000107aae7e0 -[UIControl _sendActionsForEvents:withEvent:] + 467
	9   UIKit                               0x0000000107aadbaf -[UIControl touchesEnded:withEvent:] + 522
	10  UIKit                               0x00000001079ed518 -[UIWindow _sendTouchesForEvent:] + 735
	11  UIKit                               0x00000001079ede43 -[UIWindow sendEvent:] + 683
	12  UIKit                               0x00000001079bab01 -[UIApplication sendEvent:] + 246
	13  UIKit                               0x00000001079c7bfd _UIApplicationHandleEventFromQueueEvent + 17370
	14  UIKit                               0x00000001079a2d7c _UIApplicationHandleEventQueue + 2066
	15  CoreFoundation                      0x00000001074eb9d1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	16  CoreFoundation                      0x00000001074e189d __CFRunLoopDoSources0 + 269
	17  CoreFoundation                      0x00000001074e0ed4 __CFRunLoopRun + 868
	18  CoreFoundation                      0x00000001074e0906 CFRunLoopRunSpecific + 470
	19  GraphicsServices                    0x000000010aba4a58 GSEventRunModal + 161
	20  UIKit                               0x00000001079a60e0 UIApplicationMain + 1282
	21  TaÃÇches                            0x0000000106d1f4d3 main + 115
	22  libdyld.dylib                       0x0000000109b55145 start + 1
	23  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
MasterViewController

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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