2012-11-21 248 views
1

您好,我收到錯誤的任何人都可以幫助他解決問題。 當我發送查詢到服務器時,應用程序在發送查詢到服務器之前崩潰。iPhone應用程序在[NSString stringWithFormat]崩潰

> " (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 " 

這是json的POST請求

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]; 
     //[email protected]""; 
     NSLog(@"params %@",params); 

     [[UFNetworking dataSourceInstance] getData:params toAPI:kGetMerchantList cache:NO secure:NO notification:@"getMerchantsListData"]; 
+5

可以編輯您的問題以添加代碼組成方法「['merchantListViewController getMerchantsData]'」? –

+3

請張貼一些代碼,您的應用程序崩潰.. –

+0

請張貼一些代碼來識別您的崩潰...使用異常breakPoint來查找應用程序崩潰 – Rajneesh071

回答

1

第一藉此在字符串變量的所有值,然後傳遞給字典像波紋管..

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]; 

我希望這個答案對你有幫助..

+0

謝謝帕拉斯吉 –

+0

歡迎@NagarajaYadav如果它對你有用然後接受答案和upvote請隊友 –

+0

嗨它沒有解決問題,但使我的調試很容易 –

0

我敢打賭,你有一個無效的格式的代碼。確保你沒有在int或類似的東西上使用%@

+0

它的一個搜索欄文本它怎麼可能是int它總是一個字符串(%@)但是謝謝你 –

+0

什麼是「searchMerchant」? – borrrden

+0

searchMerchant是一個nsstring價值商店在是searchbar.text –