Le code est ci-dessous:UITableView plantage lors de l'exécution délégué
@interface PreferenceViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView * preference;
UISegmentedControl * dimension;
NSArray * timeslot;
}
@property (nonatomic, retain) IBOutlet UITableView * preference;
@property (nonatomic, retain) IBOutlet UISegmentedControl * dimension;
@property (nonatomic, retain) NSArray * timeslot;
@end
- (void)viewDidLoad
{
preference.delegate = self;
preference.dataSource = self;
timeslot = [NSArray arrayWithObjects:@"7:00-8:00", @"8:00-9:00", @"9:00-10:00", @"10:00-11:00", @"11:00-12:00", @"12:00-13:00", @"13:00-14:00", @"14:00-15:00", @"15:00-16:00", @"16:00-17:00", nil];
NSLog(@"size of array is %d", [timeslot count]);
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table View delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (dimension.selectedSegmentIndex == 0){
return [timeslot count];
}else
return 15;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"TESTING");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// this is the MAGIC line!
if (dimension.selectedSegmentIndex == 0)
cell.text = [timeslot objectAtIndex:indexPath.row];
return cell;
}
Je me demandais ce qui cause l'accident? Il arrive dans ce délégué numberOfRowsInSection et l'appel à compter les intervalles de temps ..
Cela ne ferait qu'aggraver le problème. Le tableau renvoyé par '[NSArray arrayWithObjects: ...]' n'appartient pas à vous, donc autoreleasing le ferait éventuellement être relâché trop de fois. – Anomie
@Anomie Je comprends très bien le processus sous-jacent. Tu n'as pas besoin de m'apprendre. A propos de "ça le ferait éventuellement sortir trop de fois" c'est vraiment marrant. – bioffe
Alors pourquoi avez-vous posté un commentaire aussi flagrant? – Anomie