所以我做了:
我在视图控制器中放置一个表视图,然后为此设置委托和数据。然后我点击那个表视图,然后我转到xcode工具的右侧来设置DynamicPrototype并设置原型cell = 1.
我需要什么:
partner gamer pointer---> this is title i added using uiview above uitableview
(lab1) (lab2) (lab3)
50 199 144
80 112 11
30 112 14
50 100 199
50 19 44
200 500 100
Up to 25 Rows.
lab1,lab2,lab3是我在Table.xib
然后我创建subclass
uitableviewcell
。然后是代码:
Table.h
#import <UIKit/UIKit.h>
@interface TableView : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *lab1;
@property (weak, nonatomic) IBOutlet UILabel *lab2;
@property (weak, nonatomic) IBOutlet UILabel *lab3;
@end
Table.m
#import "TableView.h"
@implementation TableView
@synthesize lab1 = _lab1;
@synthesize lab2 = _lab2;
@synthesize lab3 = _lab3;
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
我编辑了viewcontroller.m
中的所有代码,此处我添加了一些json
数据:
Viewcontroller.m
#import "ViewController.h"
#import "TableView.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation ViewController
{
NSArray *jsonObject;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//NSArray *jsonObject;
jsonObject = @[
@{
@"partner": @"50",
@"gamer": @"199",
@"pointer": @"144"
},
@{
@"partner": @"80",
@"gamer": @"112",
@"pointer": @"11" },
@{
@"partner": @"30",
@"gamer": @"112",
@"pointer": @"14"
},
@{
@"partner": @"50",
@"gamer": @"100",
@"pointer": @"199"
},
@{
@"partner": @"50",
@"gamer": @"19",
@"pointer": @"44"
},
@{
@"partner": @"200",
@"gamer": @"500",
@"pointer": @"100"
}
];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSString * jsonString=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [jsonObject count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Tabel" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// cell.lab1.text = [jsonObject objectAtIndex:indexPath.row];
//cell.lab2.text = [jsonObject objectAtIndex:indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 25;
}
@end
实际上我需要向我的uitableview
显示json日期,正如我在上面的例子中所示。
在下面的方法中,我不知道如何添加我的3 label.text来升级我的json值以显示在表视图中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Tabel" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// cell.lab1.text = [jsonObject objectAtIndex:indexPath.row];
//cell.lab2.text = [jsonObject objectAtIndex:indexPath.row];
return cell;
}
请帮我解决..我跟着这2个教程Tutorial 1 [tutorial2] [2]
这是我的项目链接Here
我是初学者,自学ios。请帮我搞定
答案 0 :(得分:0)
以下是更新代码的固定和工作链接。
https://www.dropbox.com/s/jvcmpkywtrcr2p3/jsonTableView%202.zip?dl=0
请仔细搜索,仔细阅读答案,然后在此处提问。