我有一个nsmutablearray,即时尝试显示在表视图。我有一个uiviewcontroller并手动添加了表格视图。我已经通过将它拖到文件所有者的方式在xib上添加了委托和源代码。这里是我的.h文件nsmutablearray到tableview
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UILabel *label;
IBOutlet UITextField *texto;
IBOutlet UIWebView *link;
//IBOutlet UILabel *links;
IBOutlet UITextView *links;
// IBOutlet UITableView *tableView;
NSMutableArray *jsonArray;
}
@property (nonatomic,retain) IBOutlet UITableView *tableView;
//@property (nonatomic,retain) NSMutableArray *jsonArray;
-(IBAction)button;
-(IBAction)field;
-(void)populateArray;
@end
,这里是我的.m文件
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
NSString *one;
NSString *jsonreturn;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"www.myphpfile.com"];
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;
jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&error];
NSLog(@"jsonList: %@", jsonArray);
if(!jsonArray)
{
NSLog(@"Error parsing JSON:%@", error);
}
else
{
// Exception thrown here.
for(NSDictionary *item in jsonArray)
{
NSLog(@"%@", item);
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [jsonArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSLog(@"Im HERE!!!");
cell.textLabel.text = [jsonArray objectAtIndex:[indexPath row]];
NSLog(@"Cell is %@", [jsonArray objectAtIndex:indexPath.row]);
return cell;
}
我的问题是,我不能得到的细胞显示日期,我有NS记录,它表明,它是拉它,也即时获取线程1,断点1.1错误,其中的单元格创建和警告在同一行sayin tableView是本地和隐藏实例变量,任何想法?谢谢您的帮助!
更新: 我得到了我的程序编译,但它抛出一个异常: 2013年3月26日22:28:48.691你好[79888:11303] *终止应用程序由于未捕获的异常 'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:这个类不是关键字tableView的编码兼容键值。'
这是否与表中的信息不一致或即时通讯创建表错误?再次感谢!
您是否正在使用动态原型为您的表视图的故事板?如果是这样,你不需要cell = bit,那么代码将被你的故事板覆盖。 – 2013-03-26 00:47:52
首先,你下载后不要调用[tableView reloadData]。另外,你真的不应该在主线程上执行下载。我不知道你为什么得到错误。你应该发布实际的错误,而不是解释。 – rdelmar 2013-03-26 00:48:40
即时通讯仍然是新的在这里我会添加tableView reloadData?它也不是一个真正的错误,它只是停止应用程序说断点1.1,但没有错误 – paul590 2013-03-26 00:56:18