iphone - iOS crashes with EXC_BAD_ACCESS(code=1) -


i'm new ios, don't shy pointing out of code looks idiotic :)

here goes...

two view controllers - orderviewcontroller , lineitemviewcontroller - when user on lineitemviewcontroller, can click "scan" button sends request server mark item scanned. seems work fine, error in console app:

5/19/13 11:28:04.044 evoscanner: tcp_connection_destination_fail net_helper_connect_fail failed

the app still runs fine after getting error. issue when click "back" return orderviewcontroller, app crashes exc_bad_access(code=1).

i'm using xcode 4.6.2 arc enabled.

here's lineitemviewcontroller:

// interface #import <uikit/uikit.h> #import "lineitemmodel.h"  @interface lineitemviewcontroller : uiviewcontroller @property (strong, nonatomic) lineitemmodel* _line_item; -(void)setdetailitem:(lineitemmodel *) lineitem;  @property (strong, nonatomic) iboutlet uibutton *scanbutton; - (ibaction)scanitem:(id)sender;  @property (strong, nonatomic) iboutlet uilabel *itemlabel; -(ibaction)scanitem; @end  // implementation #import "lineitemviewcontroller.h" #import "lineitemmodel.h" #import "hud.h" #import "jsonmodellib.h"  @interface lineitemviewcontroller () {   lineitemmodel *_line_item; } @end  @implementation lineitemviewcontroller  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];     self.itemlabel.text = _line_item.product_title;     // additional setup after loading view. }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  -(void)setdetailitem:(id)lineitem {   if(_line_item != lineitem) {     _line_item = lineitem;      [self configureview];   } }  - (void)configureview {     // update user interface detail item.     if (self._line_item) {        // self.detaildescriptionlabel.text = [self.detailitem description];     } }  - (ibaction)scanitem:(id)sender {     nslog(@"scanning!");     nsstring *string_url = [nsstring stringwithformat:(nsstring *)@"%@/%@",  @"http://localhost:3000/api/scan_item", _line_item.id ];     nsurl *url = [nsurl urlwithstring:string_url];     nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:url];     nsstring *messagebody = [nsstring stringwithformat:@"status=%@",@1];     nsstring *msglength = [nsstring stringwithformat:@"%d", [messagebody length]];     [therequest sethttpmethod:@"post"];     [therequest addvalue: msglength forhttpheaderfield:@"content-length"];     [therequest setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];     [therequest sethttpbody:[messagebody datausingencoding:nsutf8stringencoding]];     nsurlconnection *theconnection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self];     if(theconnection)     {         nslog(@"connection successful");          //receiveddata = [[nsmutabledata data] retain];     }     else     {         nslog(@"there error: "); //        uialertview *alert1 = [[[uialertview alloc] initwithtitle:@"alert" message:@"there issue sending data. please check internet connection." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil] autorelease]; //        [alert1 show];     } } @end 

and orderviewcontroller:

// interface #import <uikit/uikit.h> #import "ordermodel.h"   @interface orderviewcontroller : uitableviewcontroller @property (strong, nonatomic) ordermodel* _order; @property (strong, nonatomic) id detailitem; @end  // implementation #import "orderviewcontroller.h" #import "ordermodel.h" #import "lineitemmodel.h" #import "lineitemcell.h" #import "hud.h" #import "jsonmodellib.h" #import "lineitemviewcontroller.h"   @interface orderviewcontroller () {     ordermodel* _order;     nsmutablearray* listofitems; } @end    @implementation orderviewcontroller  -(void)viewdidappear:(bool)animated {     nslog(@"view did appear");     // show loader view     //[hud showuiblockingindicatorwithtext:@"fetching order"];      //initialize array.     listofitems = [[nsmutablearray alloc] init];      nsmutablearray *unpackedarray = [nsmutablearray array];     nsmutablearray *packedarray = [nsmutablearray array];     nslog(@"order: %@", _order);     for(int = 0; < _order.line_items.count; i++) {         nslog(@"object in loop: %@", _order.line_items[i]);         lineitemmodel *li = _order.line_items[i];         if (li.qty_packed != li.quantity) {             [unpackedarray addobject:(lineitemmodel *)_order.line_items[i]];         } else {             [packedarray addobject:(lineitemmodel *)_order.line_items[i]];         }      }     nslog(@"unpacked array: %@", unpackedarray);     nslog(@"packed array: %@", packedarray);      nsdictionary *unpackeddict = [nsdictionary dictionarywithobject:unpackedarray forkey:@"lineitems"];       nsdictionary *packeddict = [nsdictionary dictionarywithobject:packedarray forkey:@"lineitems"];      [listofitems addobject:unpackeddict];     [listofitems addobject:packeddict];       // todo: set order id selected cell here     [self.tableview reloaddata];      self.navigationitem.title = _order.customer_name;  }    - (void)setdetailitem:(id)newdetailitem {     nslog(@"make detail item");     if (_order != newdetailitem) {         _order = newdetailitem;          // update view.         [self configureview];     }      // show loader view     [hud showuiblockingindicatorwithtext:@"fetching order"];       nsstring *order_id = _order.id;     nsstring *url = [nsstring stringwithformat:(nsstring *)@"%@/%@.%@",  @"http://localhost:3000/api/order", order_id, @"json" ];     _order = [[ordermodel alloc] initfromurlwithstring:url completion: ^(jsonmodel *model, jsonmodelerror *err) {          // hide loader view         [hud hideuiblockingindicator];          [self.tableview reloaddata];     }];   }  - (void)configureview {     // update user interface detail item.      if (_order) {        // self.detaildescriptionlabel.text = [self.detailitem description];     } }  - (id)initwithstyle:(uitableviewstyle)style {     self = [super initwithstyle:style];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     nslog(@"view did load");     [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;  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  #pragma mark - table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { #warning potentially incomplete method implementation.     // return number of sections.  1 packed items, 1 items not packed.     return [listofitems count]; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     // return number of rows in section.     nsdictionary *dictionary = [listofitems objectatindex:section];     nsarray *array = [dictionary objectforkey:@"lineitems"];     return [array count]; }   -(uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     // nslog(@"order in lineitem cell: %@", _order);      // nslog(@"lineitem: %@", line_item);      // new view code subclass     lineitemcell *cell = (lineitemcell *)[tableview dequeuereusablecellwithidentifier:@"lineitemcell"];     if (!cell) {         cell = [[lineitemcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"lineitemcell"];     }      // line item object row , section     nsdictionary *dictionary = [listofitems objectatindex:indexpath.section];     nsarray *array = [dictionary objectforkey:@"lineitems"];     lineitemmodel* line_item = [array objectatindex:indexpath.row];       cell.productlabel.text = line_item.product_title;     cell.variantlabel.text = line_item.variant_title;      int remaining = line_item.quantity - line_item.qty_packed;     cell.remaininglabel.text = [nsstring stringwithformat:@"%i", remaining];     // nslog(@"line item cell: %@", cell);     return cell; }   - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {      if(section == 0)         return @"unpacked items";     else         return @"packed items"; }   /* // 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:@[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) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {      nsindexpath *indexpath = [self.tableview indexpathforselectedrow];     nsdictionary *dictionary = [listofitems objectatindex:indexpath.section];     nsarray *array = [dictionary objectforkey:@"lineitems"];     lineitemmodel *li = [array objectatindex:indexpath.row];     nslog(@"line item in final: %@", li);       lineitemviewcontroller *vc = [segue destinationviewcontroller];     [vc setdetailitem:li]; }  - (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];      */  }    @end 

update: after setting breakpoints exceptions, trace leads me to:

#import <uikit/uikit.h>  #import "evoappdelegate.h"  int main(int argc, char *argv[]) {     @autoreleasepool {         // breakpoint leads line         // thread 1: exc_bad_access(code=1, ...)         return uiapplicationmain(argc, argv, nil, nsstringfromclass([evoappdelegate class]));     } } 

try unlinking delegate , datasource links in ib , setting delegate , datasource uitableview in orderviewcontroller programmatically


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -