2012-03-05 2 views
0

Я работаю в форме большой книги ранчо ранчо, программирование на iphone. Я работаю через 11 гл, где вы реализуете свой собственный метод setEditing:setEditing метод вызывает SIGABRT

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    if(editing) { 

     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[teams count] inSection:0]; 

     NSArray *paths = [NSArray arrayWithObject:indexPath]; 

     [[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft]; 

    } 
    else { 
     /* 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[teams count] inSection:0]; 

     NSArray *paths = [NSArray arrayWithObject:indexPath]; 

     [[self tableView] deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade]; 
     */ 
    } 
} 

Когда я запускаю это все приложение делает Sigabort без информации, кроме этого. Линия, которая, кажется, вызывает проблему, такова:

[[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft]; 

Я не уверен, что я делаю неправильно. Что еще было бы хорошо видеть?

Это весь файл:

// 
// TeamsViewController.m 
// TeamTrackerClient 
// 
// Created by Mark Steudel on 3/4/12. 
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. 
// 

#import "TeamsViewController.h" 
#import "Team.h" 

@implementation TeamsViewController 

-(id) init 
{ 
    self = [super initWithStyle:UITableViewStyleGrouped]; 

    teams = [[NSMutableArray alloc] init]; 

    Team *team = [[Team alloc] init]; 
    team.teamName = [NSString stringWithFormat: @"Fighting Axons"]; 
    team.teamCode = [NSString stringWithFormat: @"FA1"]; 

    [teams addObject:team]; 


    Team *team2 = [[Team alloc] init]; 
    team2.teamName = [NSString stringWithFormat: @"Pipers Peddlers"]; 
    team2.teamCode = [NSString stringWithFormat: @"PP1"]; 

    [teams addObject:team2]; 

    return self; 
} 

- (id) initWithStyle:(UITableViewStyle)style 
{ 
    return [self init]; 
} 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView 
{ 
} 
*/ 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
} 
*/ 

- (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); 
} 


- (UIView *) headerView 
{ 
    if(headerView) 
     return headerView; 

    UIButton *editButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

    [editButton setTitle: @"Edit" forState: UIControlStateNormal]; 

    float w = [[UIScreen mainScreen] bounds].size.width; 

    CGRect editButtonFrame = CGRectMake(8.0, 8.0, w - 16.0, 30.0); 
    [editButton setFrame:editButtonFrame]; 

    [editButton addTarget:self 
        action:@selector(editingButtonPressed:) 
     forControlEvents:UIControlEventTouchUpInside]; 

    CGRect headerViewFrame = CGRectMake(0, 0, w, 48); 
    headerView = [[UIView alloc] initWithFrame:headerViewFrame]; 

    [headerView addSubview:editButton]; 

    return headerView; 
} 


- (void) editingButtonPressed: (id) sender 
{ 
    if([self isEditing]) { 
     [sender setTitle:@"Edit" forState:UIControlStateNormal]; 

     [self setEditing:NO animated:YES]; 
    } 
    else { 
     [sender setTitle: @"Done" forState:UIControlStateNormal]; 

     [self setEditing:YES animated:YES]; 
    } 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    return [self headerView]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return [[self headerView] frame].size.height; 
} 

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{ 
    Team *t = [teams objectAtIndex:[sourceIndexPath row]]; 

    [teams removeObjectAtIndex:[sourceIndexPath row]]; 

    [teams insertObject:t atIndex:[destinationIndexPath row]]; 

} 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(editingStyle == UITableViewCellEditingStyleDelete) { 
     [teams removeObjectAtIndex:[indexPath row]]; 

     [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade]; 
    } 
} 

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    if(editing) { 

     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[teams count] inSection:0]; 

     NSArray *paths = [NSArray arrayWithObject:indexPath]; 

     [[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft]; 

    } 
    else { 
     /* 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[teams count] inSection:0]; 

     NSArray *paths = [NSArray arrayWithObject:indexPath]; 

     [[self tableView] deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade]; 
     */ 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    int numberOfRows = [teams count]; 

    if([self isEditing]) 
     numberOfRows++; 

    return numberOfRows; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; 

    if(!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"]; 
    } 

    if([indexPath row] < [teams count]) { 
     Team *t = [teams objectAtIndex:[indexPath row]]; 
     [[cell textLabel] setText:[t teamName]]; 
    } 
    else { 
     [[cell textLabel] setText: @"Add New Item ... "]; 
    } 

    Team *t = [teams objectAtIndex:[indexPath row]]; 
    [[cell textLabel] setText:[t teamName]]; 

    return cell; 
} 
@end 

ответ

0
[[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationLeft]; 

это сделать данные релоад просматривать таблицу ..и проверить данные в своих методах DATASOURCE ..

я считаю, что это сбой на

Team *t = [teams objectAtIndex:[indexPath row]]; 
[[cell textLabel] setText:[t teamName]]; 

не может быть объектов в массиве команд здесь для новых указательных путей ...

проверка путем перехвата здесь.

+0

Право! Этот фрагмент кода должен был быть удален ... спасибо! –