【发布时间】:2011-12-27 23:24:51
【问题描述】:
我有一个页面,它接收用户的邮政编码,将该数据发送到 php 页面,然后通过 JSON 检索数据。这个页面抛出一个错误,上面写着:
2011-12-27 15:17:49.919 BusinessManager[3595:20b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSConcreteData isFileURL]:发送了无法识别的选择器到实例 0x4751490'
代码是:
- (id)initWithNibName:(NSString *)SearchZip bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:SearchZip bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
- (IBAction) searchzip: (id) sender
{
NSString *post =[NSString stringWithFormat:@"zipcode=%@",zipField.text];
NSString *hostStr = @"https://www.mysite.com/searchzip.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:dataURL];
self.zipArray = [jsonData JSONValue];
[jsonData release];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [zipArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
NSDictionary *infoDictionary = [self.zipArray objectAtIndex:indexPath.row];
static NSString *Prospects = @"agencyname";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Prospects];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Prospects] autorelease];
}
// setting the text
cell.text = [infoDictionary objectForKey:@"agencyname"];
self.navigationItem.title = @"Zip Search";
// Set up the cell
return cell;
}
【问题讨论】:
标签: objective-c cocoa-touch iphone-sdk-3.0