iPhone app crash at [NSString stringWithFormat]

匿名 (未验证) 提交于 2019-12-03 10:03:01

问题:

Hi I am getting the fowling error can any one help he in solving the issue. when I am sending the query to server the app is crashing before sending the query to server.

> " (lldb) bt > * thread #1: tid = 0x2503, 0x38a4f5d0 libobjc.A.dylib`objc_msgSend + 16, stop reason = EXC_BAD_ACCESS (code=1, address=0x70706118) >     frame #0: 0x38a4f5d0 libobjc.A.dylib`objc_msgSend + 16 >     frame #1: 0x323169f0 Foundation`_NSDescriptionWithLocaleFunc + 52 >     frame #2: 0x399dc430 CoreFoundation`__CFStringAppendFormatCore + 11160 >     frame #3: 0x399538a2 CoreFoundation`_CFStringCreateWithFormatAndArgumentsAux + 74 >     frame #4: 0x3231650c Foundation`+[NSString stringWithFormat:] + 60 >     frame #5: 0x0012a92c App`-[merchantListViewController getMerchantsData] + 1344 at merchantListViewController.m:754 >     frame #6: 0x00127a3e App`-[merchantListViewController loadMoreButtonClicked:] + 194 at merchantListViewController.m:353 >     frame #7: 0x0012b0e4 App`-[merchantListViewController tableView:willDisplayCell:forRowAtIndexPath:] + 228 at > merchantListViewController.m:903 >     frame #8: 0x332565aa UIKit`-[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 514 >     frame #9: 0x3323b360 UIKit`-[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1316 >     frame #10: 0x332527fe UIKit`-[UITableView layoutSubviews] + 206 >     frame #11: 0x3320e896 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258 >     frame #12: 0x392cc4ea QuartzCore`-[CALayer layoutSublayers] + 214 >     frame #13: 0x392cc08c QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 460 >     frame #14: 0x392ccfb0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + > 16 >     frame #15: 0x392cc99a QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 238 >     frame #16: 0x392cc7ac QuartzCore`CA::Transaction::commit() + 316 >     frame #17: 0x392cc610 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, > unsigned long, void*) + 60 >     frame #18: 0x399d0940 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ > + 20 >     frame #19: 0x399cec38 CoreFoundation`__CFRunLoopDoObservers + 276 >     frame #20: 0x399cef92 CoreFoundation`__CFRunLoopRun + 746 >     frame #21: 0x3994223c CoreFoundation`CFRunLoopRunSpecific + 356 >     frame #22: 0x399420c8 CoreFoundation`CFRunLoopRunInMode + 104 >     frame #23: 0x39a9e33a GraphicsServices`GSEventRunModal + 74 >     frame #24: 0x3325f290 UIKit`UIApplicationMain + 1120 >     frame #25: 0x000dd2d8 App`main + 152 at main.m:15 " 

this is the code for the json post request

sessionId =[[NSUserDefaults standardUserDefaults] objectForKey:@"session_id"];         shouldReloadData=NO;         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getMerchantsListData:) name:@"getMerchantsListData" object:nil];         NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:                                 latitude,@"latitude",                                 longitude,@"longitude",                                 //[NSString stringWithFormat:@"%d",categoryID],@"category_id",                                 [NSString stringWithFormat:@"%d",sortOrderID],@"sort_order",                                 @"5",@"page_size",                                 [NSString stringWithFormat:@"%@",searchMerchant.text],@"search_keyword",                                 [NSString stringWithFormat:@"%d",pageNumber],@"page_number",                                 sessionId,@"session_id",                                 nil];         //searchKeyword=@"";         NSLog(@"params %@",params);          [[UFNetworking dataSourceInstance] getData:params toAPI:kGetMerchantList cache:NO secure:NO notification:@"getMerchantsListData"]; 

回答1:

first take this all value in string variable and then pass to dictionary like bellow..

   NSString *sort_order = [NSString stringWithFormat:@"%d",sortOrderID];    NSString *search_keyword = [NSString stringWithFormat:@"%@",searchMerchant.text];    NSString *page_number = [NSString stringWithFormat:@"%d",pageNumber];     NSLog(@"\n\n Sort Order ==> %@, Search_keyWord ==> %@,Page_Number ==> %@",sort_order,search_keyword,page_number); /// check here what you get from the code..     NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:                                 latitude,@"latitude",                                 longitude,@"longitude",                                 //[NSString stringWithFormat:@"%d",categoryID],@"category_id",                                 sort_order,@"sort_order",                                 @"5",@"page_size",                                 search_keyword,@"search_keyword",                                 page_number,@"page_number",                                 sessionId,@"session_id",                                 nil]; 

i hope this answer helpful to you..



回答2:

I bet you have an invalid formatter. Make sure you are not using %@ on an int or something like that.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!