objective c - Xcode 4.2 with Storyboard: Program received signal: “EXC_BAD_ACCESS” -


i'm implementing simple app storyboard has button "normal" view tableview:

enter image description here bigger picture here.

first put navigation view storyboard , put button rootview (the view "welcome!". put tableview storyboard , linked both pages locations- button in storyboard (- until didn't write code). worked until then. created locationsviewcontroller tableview, because wanted fill table view cell data.

locationsviewcontroller.m:

#import "locationsviewcontroller.h"    @interface locationsviewcontroller () {     nsarray* locations; //list of cities in our table } @end        @implementation locationsviewcontroller   - (id)initwithstyle:(uitableviewstyle)style {     self = [super initwithstyle:style];     if (self) {         // custom initialization     }     return self; }  - (void)didreceivememorywarning {     // releases view if doesn't have superview.     [super didreceivememorywarning];      // release cached data, images, etc aren't in use. }  #pragma mark - view lifecycle  - (void)viewdidload {     [super viewdidload];      // uncomment following line preserve selection between presentations.     // self.clearsselectiononviewwillappear = no;      // uncomment following line display edit button in navigation bar view controller.     // self.navigationitem.rightbarbuttonitem = self.editbuttonitem;      locations = [nsarray arraywithobjects:@"new delhi", @"durban", @"islamabad", @"johannesburg", @"kathmandu", @"dhaka", @"paris", @"rome", @"colorado springs", @"rio de janeiro", @"beijing", @"canberra", @"malaga", @"ottawa", @"santiago de chile", nil];  }  - (void)viewdidunload {     [super viewdidunload];     // release retained subviews of main view.     // e.g. self.myoutlet = nil; }  - (void)viewwillappear:(bool)animated {     [super viewwillappear:animated]; }  - (void)viewdidappear:(bool)animated {     [super viewdidappear:animated]; }  - (void)viewwilldisappear:(bool)animated {     [super viewwilldisappear:animated]; }  - (void)viewdiddisappear:(bool)animated {     [super viewdiddisappear:animated]; }  - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation {     // return yes supported orientations     return (interfaceorientation == uiinterfaceorientationportrait); }  #pragma mark - table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { #warning potentially incomplete method implementation.     // return number of sections.     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { #warning incomplete method implementation.     // return number of rows in section.     return [locations count]; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:                 uitableviewcellstyledefault reuseidentifier:cellidentifier];     }      // configure cell...      [cell.textlabel settext:[locations objectatindex:indexpath.row]];     return cell; }  /*  // override support conditional editing of table view.  - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath  {  // return no if not want specified item editable.  return yes;  }  */  /*  // override support editing table view.  - (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath  {  if (editingstyle == uitableviewcelleditingstyledelete) {  // delete row data source  [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];  }     else if (editingstyle == uitableviewcelleditingstyleinsert) {  // create new instance of appropriate class, insert array, , add new row table view  }     }  */  /*  // override support rearranging table view.  - (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)fromindexpath toindexpath:(nsindexpath *)toindexpath  {  }  */  /*  // override support conditional rearranging of table view.  - (bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath  {  // return no if not want item re-orderable.  return yes;  }  */  #pragma mark - table view delegate  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     // navigation logic may go here. create , push view controller.     /*      <#detailviewcontroller#> *detailviewcontroller = [[<#detailviewcontroller#> alloc] initwithnibname:@"<#nib name#>" bundle:nil];      // ...      // pass selected object new view controller.      [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes];      [detailviewcontroller release];      */ }  @end 

locationsviewcontroller.h:

#import <uikit/uikit.h>  @interface locationsviewcontroller : uitableviewcontroller  @end 

since declared class customclass tableview, pressing button doesn't work anymore. while running application on iphone simulator , pressing button, application freezes , message: program received signal: “exc_bad_access”.

i read problem memory management bug in code. enabled zombie-thing , got message @ point return [locations count];with console message [__nsarrayi count]: message sent deallocated instance 0x6869460. it's deallocating somewhere? how solve problem? appreciated!

one possibility use property

in .h

@property (copy, nonatomic) nsarray *locations; 

in .m

@synthesize locations; - (void)viewdidload {     [super viewdidload];     self.locations = [nsarray arraywithobjects:@"new delhi", @"durban", @"islamabad", @"johannesburg", @"kathmandu", @"dhaka", @"paris", @"rome", @"colorado springs", @"rio de janeiro", @"beijing", @"canberra", @"malaga", @"ottawa", @"santiago de chile", nil];  } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [self.locations count]; } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -