1

I am using XCode's Navigation-based Application template to create an app that centers around an UITableView. I am having some problems deleting some rows in the tableView. In all of the tableViews cells I have added a button by subclassing UITableViewCell like this:

TableViewCell.h:

@implementation TableViewCell
@synthesize button;  
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        RoutinesAppDelegate *appDelegate = (RoutinesAppDelegate *) [[UIApplication sharedApplication]delegate];

        // Initialization code
        button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
        [button setFrame:CGRectMake(320.0 - 90.0, 6.0, 80.0, 30.0)]; 
        [button setTitle:@"Done" forState:UIControlStateNormal];
        [button addTarget:appDelegate action:@selector(routineDone) forControlEvents:UIControlEventTouchUpInside];
        button.hidden = YES;
        [self.contentView addSubview:button];       
    }
    return self;
}

when the button is pressed the method "routineDone" in RoutinesAppDelegate.m is called.
The method looks like this:

RoutinesAppDelegate.m
-(void) routineDone  
{  
     if ([[NSFileManager defaultManager] fileExistsAtPath:[self todayListPath]])
     {
        int indexToRemove = buttonIndex + 1;

        todayListArray = [NSMutableArray arrayWithContentsOfFile:[self    todayListPath]];
        [todayListArray removeObjectAtIndex:indexToRemove];
        [todayListArray writeToFile:[self todayListPath] atomically:YES];
     }
}

This method removes an item from the array that the tableView loads. This works fine.

MY PROBLEM: The cell is not removed from the screen, when the button is clicked.

In RoutinesAppDelegate.m I tried to use

[tableView reloadData]

but it does not seem to work from outside the RootViewController class.

It would be nice if I somehow could use the deleteRowsAtIndexPaths method, but I dont know how to call that method from outside commitEditingStyle in the RootViewController class.

So my question is really: How can make the cell go away? :)

csano
  • 13,266
  • 2
  • 28
  • 45
steak2002
  • 177
  • 2
  • 11

1 Answers1

0

Without seeing all the code it's hard to tell, but you can try adding after

        [todayListArray writeToFile:[self todayListPath] atomically:YES];
        [self.tableView reloadData];

Also, you don't have to retain that button, and probably don't have to have it as a property