I have a table with 7 section and in each section 2 rows, I don't know why my delete button doesn't work!! and not appear in cells
would you please help me! Thanks in advance!
day.m
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
arry = [[NSMutableArray alloc] init];
[arry addObject:@"test"];
[arry addObject:@"hey"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem)];
self.navigationItem.rightBarButtonItem = rightButton;
}
-(void)addNewItem
{
[arry addObject:@"New Day"];
[self.tableView reloadData];
}
// ... standard methods to override
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 7;
//_week.days.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [arry count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.textLabel.text = [arry objectAtIndex:indexPath.row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
return @"Monday";
}
else if(section == 1)
{
return @"Tuesday";
}
else if(section == 2)
{
return @"Wednesday";
}
else if(section == 3)
{
return @"Thuesday";
}
else if(section == 4)
{
return @"Friday";
}
else if(section == 5)
{
return @"Saturday";
}
else
{
return @"Sunday";
}
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// [self.monthTitle removeObjectAtIndex:indexPath.row];
[arry removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
else if (editingStyle==UITableViewCellEditingStyleInsert)
{
}
}
Edit1: after removing multiple selection from storyboard delete button appears but when I click on delete button it's terminated