trouble with deleting uitableview rows by default method

This UITableViews gonna make me crazy!

I have UITableViewCell created by

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

doneButton = [[UIButton alloc]initWithFrame:CGRectMake(7, 15, 30, 30)];
[cell addSubview:doneButton];

cell.selectionStyle = UITableViewCellSelectionStyleNone;
[doneButton addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchDown];

UILabel *postedTime = [[UILabel alloc]initWithFrame:CGRectMake(240, 4, 60, 15)];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
postedTime.backgroundColor = [UIColor clearColor];
[cell addSubview:postedTime];
cell.textLabel.textColor = [UIColor blackColor];

UILabel *post = [[UILabel alloc] initWithFrame:CGRectMake(45, 25, 190, 30)];
[cell addSubview:post];

UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(45, 4, 180, 15)];
[cell addSubview:title];

mission *m = (mission *)[missionsArray objectAtIndex:indexPath.row];
title.text = m.title;
post.text = m.post;
postedTime.text = m.posted;

.h file:

IBOutlet UITableView *table;
NSMutableArray *missionsArray;

I'm trying to delete row by method

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

And when I click "Delete" button EXC_BAD_ACCESS. I've tried to call [missionsArray removeAllObject]; -- the same error. Then I've tried to NSLog(@"%u", indexPath.row); -- it prints right rows (when I select first row, it returns 0 and so on). Also I've tried this

if (editingStyle == UITableViewCellEditingStyleDelete) {
        [missionsArray removeObjectAtIndex:indexPath.row];
        [table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
        [table reloadData];
}

And I have no good result. Maybe cell height affects to it... Help, please. I have no idea what to do, where to search.


Problem solved. Trouble was in logical mistake when I tried to release my mission objects.

Answers


#import "ViewController.h"


@implementation ViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

    #pragma mark - View lifecycle

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        missionsArray=[[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C", nil];
    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }


    #pragma mark TableView delegate method.
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView1 {
        return 1;
    }


    - (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section 
    {
        return [missionsArray count];
    }


    - (CGFloat)tableView:(UITableView *)tableView1 heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        return 44;


    }
    - (UITableViewCell *)tableView:(UITableView *)tableView 
             cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"myCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        }

       UIButton * doneButton = [[UIButton alloc]initWithFrame:CGRectMake(7, 15, 30, 30)];
        [cell addSubview:doneButton];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [doneButton addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchDown];

        UILabel *postedTime = [[UILabel alloc]initWithFrame:CGRectMake(240, 4, 60, 15)];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        postedTime.backgroundColor = [UIColor clearColor];
        [cell addSubview:postedTime];
        cell.textLabel.textColor = [UIColor blackColor];

        UILabel *post = [[UILabel alloc] initWithFrame:CGRectMake(45, 20, 190, 30)];

        post.text=[missionsArray objectAtIndex:indexPath.row];
        [cell addSubview:post];

        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(45, 4, 180, 15)];
        [cell addSubview:title];

        return cell;

    }

        enter code here

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




    @end

Need Your Help

Can one persist MPGO data between builds?

.net optimization .net-4.5 ngen

I've just read a post about MPGO (Managed Profile Guided Optimization) and the process described is:

ForbiddenAttributesError for polymorphic model in Rails 4

parameters ruby-on-rails-4 cancan mass-assignment polymorphism

Rails 4 ships with strong_parameters, which is a great addition - but I've run into a problem with it. I have a polymorphic model Comment and I cannot for the life of me get the controller to accep...