iOS自定义表格查看单元格jSON

时间:2016-01-10 23:43:48

标签: ios json uitableview tableviewcell

我希望有人可以帮我解决这个问题。我在视图中创建了一个自定义表视图,我从服务器下载数据并将其放入表中。现在我有一个自定义单元格,在自定义单元格内部有一个名为“跟踪”的标签。一切似乎都很好但是当我去加载我的应用程序时它会崩溃并给我以下错误:

  

2016-01-10 23:34:06.107 uDropOff [88265:2009009] ***终止应用   由于未捕获的异常'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:这个类不是键   符号编码 - 符合密钥tableView。'

我希望有人可以提供帮助,我会发布单元格和下面的视图的代码。

TrackCell.h

//
//  TrackCell.h
//  uDropOff 3
//
//  Created by Curtis Boylan on 10/01/2016.
//  Copyright © 2016 Curtis Boylan. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TrackCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *tracking;


@end

TrackCell.m

//
//  TrackCell.m
//  uDropOff 3
//
//  Created by Curtis Boylan on 10/01/2016.
//  Copyright © 2016 Curtis Boylan. All rights reserved.
//

#import "TrackCell.h"

@implementation TrackCell

@synthesize tracking;


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

Track1.h

//
//  Track1.h
//  uDropOff 3
//
//  Created by Curtis Boylan on 06/01/2016.
//  Copyright © 2016 Curtis Boylan. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "TrackCell.h"

@interface Track1 : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
    IBOutlet UITableView *tableData;
}
@property(strong,nonatomic)NSArray *arr;
@property (assign, nonatomic) IBOutlet TrackCell *customCell;
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

Track1.m

//
//  Track1.m
//  uDropOff 3
//
//  Created by Curtis Boylan on 06/01/2016.
//  Copyright © 2016 Curtis Boylan. All rights reserved.
//

#import "Track1.h"
#import "TrackCell.h"

@interface Track1 ()

@end

@implementation Track1
{
    NSMutableArray *myObject;
    // A dictionary object
    NSDictionary *dictionary;
    // Define keys
    NSString *title;

}

- (void)viewDidLoad {
    [super viewDidLoad];
     [self webstuff1];
    // Do any additional setup after loading the view.
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
    [self.table addSubview:refreshControl];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)handleRefresh:(UIRefreshControl *)refresh {

    // refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];

    NSLog(@"refreshtest");
 //   [self webstuff1];
    [refresh endRefreshing];

}

- (void)webstuff1
{

    title = @"cust";
    myObject = [[NSMutableArray alloc] init];

    NSData *jsonSource = [NSData dataWithContentsOfURL:
                          [NSURL URLWithString:@"http://udropoff.com/login/driverlist.php"]];

    id jsonObjects = [NSJSONSerialization JSONObjectWithData:
                      jsonSource options:NSJSONReadingMutableContainers error:nil];

    for (NSDictionary *dataDict in jsonObjects) {
        NSString *title_data = [dataDict objectForKey:@"cust"];





        dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                      title_data, title,
                      nil];
        [myObject addObject:dictionary];
        [_table reloadData];
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return myObject.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TrackCell * cell = [tableView dequeueReusableCellWithIdentifier:(@"TrackCell")];
    if (!cell)
    {
        [tableView registerNib:[UINib nibWithNibName:@"TrackCell" bundle:nil] forCellReuseIdentifier:@"TrackCell"];
        cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"];
    }
    NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];

    NSMutableString *text;


    text = [NSMutableString stringWithFormat:@"%@",
            [tmpDict objectForKeyedSubscript:title]];


    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.backgroundColor = [UIColor clearColor];




    cell.tracking.text = text;



    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
@end

谢谢!

0 个答案:

没有答案