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

Windows 8.1 XAML - LayoutTransform

c# windows-runtime custom-controls winrt-xaml windows-8.1

I'm trying to use the LayoutTransform property to rotate some text 90 degrees in a windows 8.1/VS2013 template.

Pass certain value safely to webapp for that session trough url

c# security url session-variables

I am building a web app in c# and I have the following question.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.