我已经尝试了很多东西来完成这项工作而且我完全失败了。
我收到以下错误
-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x4d41210
2011-01-31 17:03:49.496 IHaulage[11954:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x4d41210
我的代码如下所示
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"FIRST LINE ROW");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
hold = [self.names objectAtIndex:[indexPath row]];
//NSString *hold = [big objectAtIndex:indexPath.row];
//NSLog(@"%@",hold);
//hold = @"TEST TEST";
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.textLabel.text = hold;
return cell;
}
如果我取消注释hold = @"test test"
表格正确填充“test test”
- (void)viewDidLoad {
self.names = [NSMutableArray arrayWithObjects:@"Hi",nil];
DataManager *sharedManager = [DataManager sharedManager];
[activityIndicator startAnimating];
NSString *soapMsg = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap= \"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\" > "
"<soap:Header/>"
"<soap:Body>"
"<tem:LookupContractors>"
"<tem:haulerId>%@</tem:haulerId>"
"</tem:LookupContractors>"
"</soap:Body>"
"</soap:Envelope>",sharedManager.userID];
NSLog(sharedManager.userID);
NSURL *url = [NSURL URLWithString:@"http://ihaulage.com/wcf/haulageservice.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/IHaulageService/LookupContractors" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest: theRequest delegate:self];
if(conn)
{
webData = [[NSMutableData data] retain];
} else {
NSLog(@"theConnection is NULL");
}
if (xmlParser)
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
[super viewDidLoad];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
if (xmlParser)
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
if (elementFound)
{
SBJSON *parser = [[SBJSON alloc] init];
statuses = (NSArray *)[parser objectWithString:string error:nil];
for (NSDictionary *status in statuses)
{
[self.names addObject:[status objectForKey:@"Name"]];
NSLog(@"%@",[status objectForKey:@"Name"]);
NSLog(@"%@ - %@ - %@ - %@ - %@",[status objectForKey:@"ID"], [status objectForKey:@"Name"],[status objectForKey:@"Fax"],[status objectForKey:@"Email"],[status objectForKey:@"company"]);
}
NSLog(@"%@",[names objectAtIndex:1]);
[parser release];
[contractor_list reloadData];
[activityIndicator stopAnimating];
}
}
@interface ManageContractors : UIViewController {
IBOutlet UITableView *contractor_list;
NSArray *statuses;
NSString *hold;
NSString *current;
IBOutlet UIActivityIndicatorView *activityIndicator;
//---web service access---
NSMutableData *webData;
NSMutableString *soapResults;
NSURLConnection *conn;
NSMutableArray *names;
//---xml parsing---
NSXMLParser *xmlParser;
BOOL *elementFound;
BOOL *table;
}
@property (nonatomic,retain) UITableView *contractor_list;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic,retain) NSMutableArray *names;
@end
对于大量的代码感到抱歉,但我想如果我展示了更多代码,我可以获得更多帮助
我不知道导致此错误的原因。我的Json解析是正确的,我的名字数组填写正确,当我想把它显示到完全崩溃的表时
2011-02-01 10:11:40.606 IHaulage[15827:207] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x9b29560
2011-02-01 10:11:40.607 IHaulage[15827:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x9b29560'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db9be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0e5c2 objc_exception_throw + 47
2 CoreFoundation 0x00dbb6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d2b366 ___forwarding___ + 966
4 CoreFoundation 0x00d2af22 _CF_forwarding_prep_0 + 50
5 UIKit 0x003e1340 -[UILabel setText:] + 72
6 IHaulage 0x0000746e -[ManageContractors tableView:cellForRowAtIndexPath:] + 434
7 UIKit 0x003367fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x0032c77f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x00341450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x00339538 -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01c77451 -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01c7717c CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01c7037c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01c700d0 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01ca07d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00d9afbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d300e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00cf8bd7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00cf8240 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00cf8161 CFRunLoopRunInMode + 97
21 GraphicsServices 0x016ee268 GSEventRunModal + 217
22 GraphicsServices 0x016ee32d GSEventRun + 115
23 UIKit 0x002d142e UIApplicationMain + 1160
24 IHaulage 0x00001ad8 main + 102
25 IHaulage 0x00001a69 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
愚蠢的是我在使用断点
进行调试时所做的堆栈跟踪日志#0 -[ManageContractors tableView:cellForRowAtIndexPath:] (self=0x4b56490, _cmd=0x6dfd5f, tableView=0x5048c00, indexPath=0x8d163f0) at /Users/mdedys/Dropbox/iHaulage Code/iPhone/IHaulage/Classes/ManageContractors.m:49
#1 0x003367fa in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] ()
#2 0x0032c77f in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] ()
#3 0x00341450 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] ()
#4 0x00339538 in -[UITableView layoutSubviews] ()
#5 0x01c77451 in -[CALayer layoutSublayers] ()
#6 0x01c7717c in CALayerLayoutIfNeeded ()
#7 0x01c7037c in CA::Context::commit_transaction ()
#8 0x01c700d0 in CA::Transaction::commit ()
#9 0x01ca07d5 in CA::Transaction::observer_callback ()
#10 0x00d9afbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#11 0x00d300e7 in __CFRunLoopDoObservers ()
#12 0x00cf8bd7 in __CFRunLoopRun ()
#13 0x00cf8240 in CFRunLoopRunSpecific ()
#14 0x00cf8161 in CFRunLoopRunInMode ()
#15 0x016ee268 in GSEventRunModal ()
#16 0x016ee32d in GSEventRun ()
#17 0x002d142e in UIApplicationMain ()
#18 0x00001ad8 in main (argc=1, argv=0xbfffeff0) at /Users/mdedys/Dropbox/ihaulage code/iPhone/IHaulage/main.m:14
答案 0 :(得分:2)
问题是nss指出我的数据不是字符串。我把它展示在桌子上时不得不把它扔掉。
cell.textLabel.text = [[self.names objectAtIndex:indexPath.row]description]
关键词是描述,将其转换为字符串