ios - iphone app click delete crash -
in application when press delete row crash. tried find solution problem already, hope can me solve it.
my code here:
firstview.h
#import <uikit/uikit.h> @interface firstview : uiviewcontroller <uitextfielddelegate,uitableviewdatasource,uitableviewdelegate>{ iboutlet uitableview *tableview; iboutlet uidatepicker *datepicker; iboutlet uitextfield *eventtext; nsarray *notificationarray; nsmutablearray *array; } @property (nonatomic, retain) iboutlet uitableview *tableview; @property (nonatomic, retain) iboutlet uidatepicker *datepicker; @property (nonatomic, retain) iboutlet uitextfield *eventtext; - (ibaction) schedulealarm:(id) sender; @end firstview.m
#import "firstview.h" @implementation firstview @synthesize datepicker, eventtext,tableview; - (void) viewwillappear:(bool)animated { [self.tableview reloaddata]; } - (ibaction) schedulealarm:(id) sender { [eventtext resignfirstresponder]; nscalendar *calendar = [nscalendar autoupdatingcurrentcalendar]; // current date nsdate *pickerdate = [self.datepicker date]; // break date components nsdatecomponents *datecomponents = [calendar components:( nsyearcalendarunit | nsmonthcalendarunit | nsdaycalendarunit ) fromdate:pickerdate]; nsdatecomponents *timecomponents = [calendar components:( nshourcalendarunit | nsminutecalendarunit | nssecondcalendarunit ) fromdate:pickerdate]; // set fire time nsdatecomponents *datecomps = [[nsdatecomponents alloc] init]; [datecomps setday:[datecomponents day]]; [datecomps setmonth:[datecomponents month]]; [datecomps setyear:[datecomponents year]]; [datecomps sethour:[timecomponents hour]]; // notification fire in 1 minute [datecomps setminute:[timecomponents minute]]; [datecomps setsecond:[timecomponents second]]; nsdate *itemdate = [calendar datefromcomponents:datecomps]; [datecomps release]; uilocalnotification *localnotif = [[uilocalnotification alloc] init]; if (localnotif == nil) return; localnotif.firedate = itemdate; localnotif.timezone = [nstimezone defaulttimezone]; // notification details localnotif.alertbody = [eventtext text]; // set action button localnotif.alertaction = @"view"; localnotif.soundname = uilocalnotificationdefaultsoundname; localnotif.applicationiconbadgenumber = 1; // specify custom data notification nsdictionary *infodict = [nsdictionary dictionarywithobject:@"somevalue" forkey:@"somekey"]; localnotif.userinfo = infodict; // schedule notification [[uiapplication sharedapplication] schedulelocalnotification:localnotif]; [localnotif release]; [self.tableview reloaddata]; } // designated initializer. override if create controller programmatically , want perform customization not appropriate viewdidload. /* - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization. } return self; } */ // implement viewdidload additional setup after loading view, typically nib. - (void)viewdidload { eventtext.delegate = self; array = [notificationarray mutablecopy]; [super viewdidload]; } #pragma mark - #pragma mark table view data source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return [[[uiapplication sharedapplication] scheduledlocalnotifications] count]; } // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; } // configure cell... notificationarray = [[uiapplication sharedapplication] scheduledlocalnotifications]; uilocalnotification *notif = [notificationarray objectatindex:indexpath.row]; [cell.textlabel settext:notif.alertbody]; [cell.detailtextlabel settext:[notif.firedate description]]; return cell; } - (void)tableview:(uitableview *)tv commiteditingstyle: (uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { // if row deleted, remove list. if (editingstyle == uitableviewcelleditingstyledelete) { [array removeobjectatindex:indexpath.row]; [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; } } /* // override allow orientations other default portrait orientation. - (bool)shouldautorotatetointerfaceorientation: (uiinterfaceorientation)interfaceorientation { // return yes supported orientations. return (interfaceorientation == uiinterfaceorientationportrait); } */ - (bool)textfieldshouldreturn:(uitextfield *)thetextfield { [eventtext resignfirstresponder]; return yes; } - (void)didreceivememorywarning { // releases view if doesn't have superview. [super didreceivememorywarning]; // release cached data, images, etc. aren't in use. } - (void)viewdidunload { [super viewdidunload]; // release retained subviews of main view. // e.g. self.myoutlet = nil; datepicker = nil; eventtext = nil; } - (void)dealloc { [super dealloc]; } @end the crash log here.
2011-04-12 13:27:26.860 sms timer[2050:207] *** assertion failure in -[uitableview _endcellanimationswithcontext:], /sourcecache/uikit_sim/uikit-1448.89/uitableview.m:995 2011-04-12 13:27:26.863 sms timer[2050:207] *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of rows in section 0. number of rows contained in existing section after update (5) must equal number of rows contained in section before update (5), plus or minus number of rows inserted or deleted section (0 inserted, 1 deleted).' *** call stack @ first throw: ( 0 corefoundation 0x00dca5a9 __exceptionpreprocess + 185 1 libobjc.a.dylib 0x00f1e313 objc_exception_throw + 44 2 corefoundation 0x00d82ef8 +[nsexception raise:format:arguments:] + 136 3 foundation 0x000b53bb -[nsassertionhandler handlefailureinmethod:object:file:linenumber:description:] + 116 4 uikit 0x00338e8b -[uitableview(_uitableviewprivate) _endcellanimationswithcontext:] + 8420 5 uikit 0x00327cf8 -[uitableview deleterowsatindexpaths:withrowanimation:] + 56 6 sms timer 0x00003414 -[firstview tableview:commiteditingstyle:forrowatindexpath:] + 189 7 uikit 0x00325037 -[uitableview(uitableviewinternal) animatedeletionofrowwithcell:] + 101 8 uikit 0x002ba4fd -[uiapplication sendaction:to:from:forevent:] + 119 9 uikit 0x0034a799 -[uicontrol sendaction:to:forevent:] + 67 10 uikit 0x0034cc2b -[uicontrol(internal) _sendactionsforevents:withevent:] + 527 11 uikit 0x0034b7d8 -[uicontrol touchesended:withevent:] + 458 12 uikit 0x002deded -[uiwindow _sendtouchesforevent:] + 567 13 uikit 0x002bfc37 -[uiapplication sendevent:] + 447 14 uikit 0x002c4f2e _uiapplicationhandleevent + 7576 15 graphicsservices 0x01722992 purpleeventcallback + 1550 16 corefoundation 0x00dab944 __cfrunloop_is_calling_out_to_a_source1_perform_function__ + 52 17 corefoundation 0x00d0bcf7 __cfrunloopdosource1 + 215 18 corefoundation 0x00d08f83 __cfrunlooprun + 979 19 corefoundation 0x00d08840 cfrunlooprunspecific + 208 20 corefoundation 0x00d08761 cfrunloopruninmode + 97 21 graphicsservices 0x017211c4 gseventrunmodal + 217 22 graphicsservices 0x01721289 gseventrun + 115 23 uikit 0x002c8c93 uiapplicationmain + 1160 24 sms timer 0x00002754 main + 102 25 sms timer 0x000026e5 start + 53 ) terminate called after throwing instance of 'nsexception'
- (void)tableview:(uitableview *)tv commiteditingstyle: (uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { // if row deleted, remove list. if (editingstyle == uitableviewcelleditingstyledelete) { [array removeobjectatindex:indexpath.row]; [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; //try set count line //[[[uiapplication sharedapplication] scheduledlocalnotifications] count];if getting proper after deleting cell, won;t crash.since deleting cell not updating count still return 5 intend of 4 after deleting data. [self.tableview reloaddata]; } hope works...lets give hand on
Comments
Post a Comment