2013-03-26 47 views
0

我有一个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的编码兼容键值。'

这是否与表中的信息不一致或即时通讯创建表错误?再次感谢!

+0

您是否正在使用动态原型为您的表视图的故事板?如果是这样,你不需要cell = bit,那么代码将被你的故事板覆盖。 – 2013-03-26 00:47:52

+0

首先,你下载后不要调用[tableView reloadData]。另外,你真的不应该在主线程上执行下载。我不知道你为什么得到错误。你应该发布实际的错误,而不是解释。 – rdelmar 2013-03-26 00:48:40

+0

即时通讯仍然是新的在这里我会添加tableView reloadData?它也不是一个真正的错误,它只是停止应用程序说断点1.1,但没有错误 – paul590 2013-03-26 00:56:18

回答

0

如果你已经通过界面生成器/分镜尝试添加添加的实现代码如下:

@synthesize tableView; 

在.m文件的@implementation下。然后确保你的桌面视图在你的IB中正确连接。 (向视图控制器作为两个数据源和委托,然后形成VC到的tableview为的tableView。)

0
NSString *one; 
NSString *jsonreturn; 

这两个语句缺乏标准化。

如果你还没有使用ARC,jsonreturn会泄漏。

0

由于您有一个名为tableView的实例变量,并且在表视图数据源方法tableView作为参数传递进来,您将收到警告。更改此变量名称或实例变量名称将解决该问题。既然他们都指的是同样的事情,那没关系。

如果它刚刚停止在说Stopping at Breakpoint 1的点上,那么你可能已经设置了一个断点。它看起来像一个蓝色的箭头标记,位于代码的左侧。您可以通过再次单击(变成较亮的阴影)或删除它来禁用它 - 将断点拖出或右键单击断点并删除。

Breakpoint

0

看看你tablview的变量名

IBOutlet UITableView *tableView 

其作为UITableView的内置方法同样使用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

所以它给你的警告,“的tableView是本地和隐藏实例变量“

为了避免它只是改变你的UITableView变量名为“myTableView”

0

首先分配您的NSMutableArray,像这样“ArrayName = [[NSMutableArray alloc] init];