我試圖在UITableview
中顯示我的記錄。我可以得到json數據。問題開始於UITableViewCell
。UITableview NSarray isEqualToString無法識別的選擇器發送到實例
-(void)getData {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString;
dateString = [dateFormatter stringFromDate:[NSDate date]];
NSDictionary *params = @{@"tarih":dateString,@"email":@"[email protected]",@"token":@"token",@"id":@"11"};
NSString *url = [NSString stringWithFormat:@"http://crm.mywebsite.com/api/sync.php"];
[manager POST:url parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&testerror];
NSLog(@"%@",dataDictionary);
_customerList = [NSMutableArray array];
NSArray *customerArray = [dataDictionary valueForKey:@"kart"];
for (NSDictionary *customerDictionary in customerArray) {
NKart *card = [NKart taskWithTitle:[customerDictionary valueForKey:@"adi"]];
card.adres = [customerDictionary valueForKey:@"adres"];
NSLog(@"%@",card.adres);
[self.customerList addObject:card];
[self.tableView reloadData];
}
} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
NSLog(@"Error: %@",error);
}];
cellForRowAtIndexPath
方法。
NKart *card = [_customerList objectAtIndex:indexPath.row];
cell.textLabel.text= card.adi;
當我試圖在tableview中顯示它們時,我遇到了這個錯誤。
[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x7fe04b8b5a00
2015-10-16 16:08:25.503 SaphiraCrmm[6271:2023549] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x7fe04b8b5a00'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c511f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bf8bdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010c51a58d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010c467f7a ___forwarding___ + 970
4 CoreFoundation 0x000000010c467b28 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010cd3590f -[UITableViewLabel setText:] + 119
6 SaphiraCrmm 0x000000010ad24d95 -[CustomerListTableViewController tableView:cellForRowAtIndexPath:] + 997
7 UIKit 0x000000010ca0d6b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
8 UIKit 0x000000010ca0d7c8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
9 UIKit 0x000000010c9e3650 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
10 UIKit 0x000000010ca16595 -[UITableView _performWithCachedTraitCollection:] + 92
11 UIKit 0x000000010c9fe9ad -[UITableView layoutSubviews] + 218
12 UIKit 0x000000010c96f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
13 QuartzCore 0x00000001107c636a -[CALayer layoutSublayers] + 146
14 QuartzCore 0x00000001107babd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
15 QuartzCore 0x00000001107baa4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x00000001107af1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
17 QuartzCore 0x00000001107dc9f0 _ZN2CA11Transaction6commitEv + 508
18 QuartzCore 0x00000001107dd154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
19 CoreFoundation 0x000000010c43d9d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x000000010c43d947 __CFRunLoopDoObservers + 391
21 CoreFoundation 0x000000010c43359b __CFRunLoopRun + 1147
22 CoreFoundation 0x000000010c432e98 CFRunLoopRunSpecific + 488
23 GraphicsServices 0x000000011027bad2 GSEventRunModal + 161
24 UIKit 0x000000010c8be676 UIApplicationMain + 171
25 SaphiraCrmm 0x000000010ad297af main + 111
26 libdyld.dylib 0x000000010e5f592d start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
阿迪不是NSArray的
還有就是JSON
{
adi = "TestFirm";
adi2 = "";
adi3 = "";
adres = "\U0130STANBUL";
email = "";
email2 = "";
facebook = "";
fax = "";
"fk_agent" = 2;
"fk_faaliyet_alani" = 0;
"fk_grubu" = 7;
"fk_il" = 34;
"fk_kaydi_yapan" = 0;
"fk_kaynagi" = 0;
id = 407;
"kayit_tipi" = 10;
ktar = "2014-10-30 16:28:00";
linkedin = "";
skype = "";
tel1 = "";
tel2 = "";
twitter = "";
vd = "";
vn = "";
www = "";
}
所以我'確保其未來的字符串給我。
這很容易解決。嘗試在完成解析後添加斷點。你會看到一個數組賦予一個字符串期望對象。在你實例化你的單元之前再檢查一下。 – erenkabakci
我已經在 中做過了cell.textLabel.text = card.adi; 其崩潰。 –
有些東西一定是錯的card.adi –