您好,我是 Cocoa Development 的新手,我正试图找出我做错了什么。我遵循了一个(教程),它使用 touchJSON 在 Xcode 中使用 mySQL 数据库填充 tableView。当我运行应用程序时,一切正常,但是当我向下滚动 tableView 时出现NSInvalidExeption
错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[NSNull isEqualToString:]: unrecognized selector sent to
instance 0x1469cd8'
我真的不知道这是否与 php 代码(和数据库)或 Xcode 中的代码有关。
这是我的 php 代码:
<?php
$link = mysql_pconnect("localhost", "root", "root") or die("Could not connect");
mysql_select_db("PartyON") or die("Could not select database");
$arr = array();
$rs = mysql_query("SELECT id, Maand, Naam, Locatie, Plaats FROM tblWebData");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{"tblWebData":'.json_encode($arr).'}';
?>
这是我的 Xcode 代码:
#import "GentDataView.h"
#import "CJSONDeserializer.h"
#import "GentDetailCell.h"
@implementation GentDataView
@synthesize rows, tableview;
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://localhost:8888/example3.php"]; //URL Modification
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; // Pulls the URL
// NSLog(jsonreturn); // Look at the console and you can see what the restults are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
if (dict)
{
rows = [dict objectForKey:@"tblWebData"];
}
NSLog(@"Array: %@",rows);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rows count];
}
// Customize the appearance of table view cells.
- (GentDetailCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
GentDetailCell *cell = (GentDetailCell *) [tableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GentDetailCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell.
NSSortDescriptor *sorteerDiscriptor = [[NSSortDescriptor alloc] initWithKey:@"id" ascending:NO];
rows = [rows sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorteerDiscriptor]];
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
cell.Naam.text = [dict objectForKey:@"Naam"];
cell.Plaats.text = [dict objectForKey:@"Plaats"];
cell.Maand.text = [dict objectForKey:@"Maand"];
cell.Locatie.text = [dict objectForKey:@"Locatie"];
cell.imageView.image = [NSURL URLWithString:@"http://www.iconarchive.com/show/flags-icons-by-iconscity/belgium-icon.html"];
//cell.textLabel.text = [dict objectForKey:@"post_title"];
//cell.detailTextLabel.text = [dict objectForKey:@"post_content"];
//tableView.backgroundColor = [UIColor cyanColor];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 125;
}
@end
正如我已经告诉我的那样,我是新手,所以非常欢迎任何帮助!我试图弄清楚这个问题好几天了,但我似乎找不到准确的答案或解决方案!
非常感谢您提前付出的努力!