非常熟悉Android編程,但對於iOS(和Objective-C)來說非常新穎。使用NSDictionary填充UITableView包含從MySQL數據庫分析的JSON數據
我在我的應用程序和(我相信)根據我的NSLOG結果成功解析JSON結果調用遠程php文件。例如:
2013-01-17 14:24:30.611 JSON TESTING 4[1309:1b03] Deserialized JSON Dictionary = {
products = (
{
BF = "";
EN = "2342";
Measure = ft;
Name = "Brian";
"Name_id" = 1;
Home = "New York";
"DB_id" = 1;
},
{
BF = "";
EN = "2123";
Measure = ft;
Name = "Rex";
"Name_id" = 3;
Home = "New York";
"DB_id" = 5;
}
);
success = 1;
}
我的問題在於如何填充此信息到表視圖。我可以自定義一個原型單元格,但我從哪裏去?
編輯:
這裏是我的視圖設置代碼:
#pragma mark - Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return productArray.count;
NSLog(@"Number of arrays %u", productArray.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];
}
NSDictionary *productDictionary = [productArray objectAtIndex:indexPath.row];
cell.textLabel.text = [productDictionary objectForKey:@"BF"];
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self launchTest];
}
和我的.h文件
@interface tpbaMasterViewController : UITableViewController
{
NSDictionary *lists;
NSArray *productArray;
}
- (void) launchTest;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end
lists =(NSDictionary *)jsonObject; productArray = [列出objectForKey:@「products」]; – ADK