- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
I want to like this, Please have a look
我有 UITableViewCell 并且我创建了按类别排列的 JSON 数据。我获取了我们所有的值,但如何在特定数组中安排类别,例如两个不同数组下的“business_details”中的第一个类别“Automotive”。我想在 UITableViewCell 中安排类别。怎么可能,请帮助。谢谢你
{
"status": [
{
"business_category_name": "Automotive",
"business_details": [
{
"img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1467813900-263.jpg",
"name": "ssmpl",
"des": "SIXTH SENSE MARKETING PVT LTD",
"address": "m2",
"email": "hr@sixthsenseit.com",
"phone": "09999999999",
"member_since": "2016-07-06",
"img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1467813900-263.jpg",
"website": "www.sixthsenseit.com",
"city": "indore",
"state": "mp",
"zip": "452001"
},
{
"img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1467814186-DSC_5854.jpg11.jpg",
"name": "h",
"des": "",
"address": "gkjg",
"email": "jgjg",
"phone": "gjg",
"member_since": "2016-07-06",
"img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1467814186-DSC_5854.jpg11.jpg",
"website": "jg",
"city": "jg",
"state": "gjg",
"zip": "jgj"
}
]
},
{
"business_category_name": "Banks\/Credit Unions\/Landers",
"business_details": [
{
"img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg",
"name": "PNC Bank",
"des": "PNC offers a wide range of services for all our customers, from individuals and small businesses, to corporations and government entities",
"address": "",
"email": "andrea.kendall@pnc.com",
"phone": "260-422-5922",
"member_since": "2016-05-31",
"img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg",
"website": "",
"city": "Fort Wayne",
"state": "IN",
"zip": "46808"
}
]
}
]
}
- (void)viewDidLoad
{
[super viewDidLoad];
names = [NSMutableArray new];
ntm= [NSMutableArray new];
adrsary=[NSMutableArray new];
phoneary=[NSMutableArray new];
emailary=[NSMutableArray new];
websiteary=[NSMutableArray new];
sensary=[NSMutableArray new];
desary=[NSMutableArray new];
image=[NSMutableArray new];
[self.tabel_view setAllowsMultipleSelection:YES];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_member.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *statuses = [json objectForKey:@"status"];
for(NSDictionary *status in statuses){
NSString *bussiness_category=[status valueForKey:@"business_category_name"];
[names addObject:bussiness_category];
NSLog(@"busness details %@",names);
for(NSDictionary *details in [status objectForKey:@"business_details"])
{
NSString *name=[details valueForKey:@"name"];
[ntm addObject:name];
NSLog(@"name %@",ntm);
NSString *address=[details valueForKey:@"address"];
[adrsary addObject:address];
NSLog(@"address %@",adrsary);
NSString *phone=[details valueForKey:@"phone"];
[phoneary addObject:phone];
NSLog(@"phone %@",phoneary);
NSString *email=[details valueForKey:@"email"];
[emailary addObject:email];
NSLog(@"email %@",emailary);
NSString *website=[details valueForKey:@"website"];
[websiteary addObject:website];
NSLog(@"website %@",websiteary);
NSString *memsens=[details valueForKey:@"member_since"];
[sensary addObject:memsens];
NSLog(@"mem. sense %@",sensary);
NSString *des=[details valueForKey:@"des"];
[desary addObject:des];
NSLog(@"desc. %@",desary);
NSString *img=[details valueForKey:@"img_url"];
[image addObject:img];
NSLog(@"image. %@",image);
}
}
for (int i=0; i<[names count]; i++) {
[arrayForBool addObject:[NSNumber numberWithBool:NO]];
}
[self.tabel_view reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return names.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[arrayForBool objectAtIndex:section] boolValue]) {
return emailary.count;
}
else
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 70;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,70)];
sectionHeaderView.backgroundColor=[UIColor grayColor];
sectionHeaderView.tag=section;
UIView *sectionsubHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,60)];
sectionsubHeaderView.backgroundColor=[UIColor blueColor];
UIImageView *arrow=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,60, 60)];
[arrow setImage:[UIImage imageNamed:@"arrow"]];
UILabel *Lbl=[[UILabel alloc]initWithFrame:CGRectMake(60, 0,tableView.frame.size.width-60, 60)];
Lbl.text=[names objectAtIndex:section];
Lbl.textColor=[UIColor whiteColor];
[sectionsubHeaderView addSubview:arrow];
[sectionsubHeaderView addSubview:Lbl];
[sectionHeaderView addSubview:sectionsubHeaderView];
UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
[sectionHeaderView addGestureRecognizer:headerTapped];
return sectionHeaderView;
}
- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag];
if (indexPath.row == 0) {
BOOL collapsed = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
for (int i=0; i<[names count]; i++) {
if (indexPath.section==i) {
[arrayForBool replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:!collapsed]];
}
}
[self.tabel_view reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.title.text=[NSString stringWithFormat:@"%@",[ntm objectAtIndex:indexPath.row]];
cell.email.text=[NSString stringWithFormat:@"%@",[emailary objectAtIndex:indexPath.row]];
cell.address_lbl.text=[NSString stringWithFormat:@"%@",[adrsary objectAtIndex:indexPath.row]];
cell.phone_lbl.text=[NSString stringWithFormat:@"%@",[phoneary objectAtIndex:indexPath.row]];
cell.web_lbl.text=[NSString stringWithFormat:@"%@",[websiteary objectAtIndex:indexPath.row]];
cell.sens_lbl.text=[NSString stringWithFormat:@"%@",[sensary objectAtIndex:indexPath.row]];
cell.des_lbl.text=[NSString stringWithFormat:@"%@",[desary objectAtIndex:indexPath.row]];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [image objectAtIndex:indexPath.row]]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
cell.image_view.image =image;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[arrayForBool replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:NO]];
[self.tabel_view reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
最佳答案
试试这个-
采用全局数组,即 NSMutableArray *arrayForBool;
与您的其他数组。在 viewDidLoad()
中分配这个数组,即 arrayForBool=[[NSMutableArray alloc]init];
现在将这些代码行添加到 connectionDidFinishLoading
之前[tableview reloadData]
-
for (int i=0; i<[names count]; i++) {
[arrayForBool addObject:[NSNumber numberWithBool:NO]];
}
这是完整的代码-
#import "ViewController.h"
#import "MemberTableViewCell.h"
#import "secondVC.h"
@interface ViewController ()
{
NSMutableData *response;
NSMutableArray *arrayForBool;
NSMutableArray *business_details_array;
NSMutableArray *names;
NSDictionary *passDict;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
names = [NSMutableArray new];
arrayForBool=[[NSMutableArray alloc]init];
[self.tableView setAllowsMultipleSelection:YES];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_member.php"]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if( connection )
{
response = [NSMutableData new];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response1
{
[response setLength:0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSArray *statuses = [json objectForKey:@"status"];
names=[[NSMutableArray alloc]initWithArray:[statuses valueForKey:@"business_category_name"]];
business_details_array=[[NSMutableArray alloc]initWithArray:[statuses valueForKey:@"business_details"]];
for (int i=0; i<[names count]; i++) {
[arrayForBool addObject:[NSNumber numberWithBool:NO]];
}
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return names.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[arrayForBool objectAtIndex:section] boolValue]) {
return [[business_details_array objectAtIndex:section] count];
}
else
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 70;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,70)];
sectionHeaderView.backgroundColor=[UIColor grayColor];
sectionHeaderView.tag=section;
UIView *sectionsubHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,60)];
sectionsubHeaderView.backgroundColor=[UIColor blueColor];
UIImageView *arrow=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,60, 60)];
[arrow setImage:[UIImage imageNamed:@"arrow.png"]];
UILabel *Lbl=[[UILabel alloc]initWithFrame:CGRectMake(60, 0,tableView.frame.size.width-60, 60)];
Lbl.text=[names objectAtIndex:section];
Lbl.textColor=[UIColor whiteColor];
[sectionsubHeaderView addSubview:arrow];
[sectionsubHeaderView addSubview:Lbl];
[sectionHeaderView addSubview:sectionsubHeaderView];
UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
[sectionHeaderView addGestureRecognizer:headerTapped];
return sectionHeaderView;
}
- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag];
if (indexPath.row == 0) {
BOOL collapsed = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
for (int i=0; i<[names count]; i++) {
if (indexPath.section==i) {
[arrayForBool replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:!collapsed]];
}
}
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.title.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"name"] objectAtIndex:indexPath.row]];
cell.email.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"email"] objectAtIndex:indexPath.row]];
cell.address_lbl.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"address"] objectAtIndex:indexPath.row]];
cell.phone_lbl.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"phone"] objectAtIndex:indexPath.row]];
cell.web_lbl.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"website"] objectAtIndex:indexPath.row]];
cell.sens_lbl.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"member_since"] objectAtIndex:indexPath.row]];
cell.des_lbl.text=[NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"des"] objectAtIndex:indexPath.row]];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@",[[[business_details_array objectAtIndex:indexPath.section] valueForKey:@"img_url"] objectAtIndex:indexPath.row]]]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
cell.image_view.image =image;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[arrayForBool replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:NO]];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
passDict=[[business_details_array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"gotoSeconVC" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"gotoSeconVC"]) {
secondVC *vc=[segue destinationViewController];
vc.myPreviousVCDict=passDict;
}
}
@end
现在在 secondVC.h
文件中-
#import <UIKit/UIKit.h>
@interface secondVC : UIViewController
@property(strong,nonatomic)NSDictionary *myPreviousVCDict;
@end
NSLog()
这个字典在 viewDidLoad()
中。希望对你有帮助。使用它,您可以制作部分和可扩展部分的自定义标题。
这是输出屏幕-
storyBoard 必须看起来像这样-
这就是您想要的 member_details--
关于ios - 如何在类别中创建 UITableViewCell 明智地排列 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38238027/
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 9 个月前关闭。 Improve
我使用 partykit打包并遇到以下错误消息: Error in matrix(0, nrow = mi, ncol = nl) : invalid 'nrow' value (too large
我一直在尝试寻找一个量表或分类指标,为 VADER 情绪分析分配一些情感程度,而不仅仅是积极、消极或中性。如果有人可以分享他们的观点或资源来帮助按以下方式对 VADER 复合分数进行分类,我将非常感激
伙计们,我想自动循环..但我不知道是我放错了 while 还是循环错了? 我的数据库 标签:kt_barang kd_kategori | nama_kategori 1
我正在创建一个列出本地企业并按类别、子类别和关键字对它们进行分组的应用程序。以下是企业排序规则: 一个企业可以属于多个类别和子类别 一个企业可以有多个关键字 并非每个类别都有子类别,但有子类别的只有两
我有一系列单词 - 我的刺激 - 它们显示在屏幕上。然而,每个词都有另一个“条件”,即它们是类别 A、类别 B 或类别 C。这可能很简单,但我找不到答案并坚持下去。我的最终目标是在每次运行脚本时将类别
我正在使用 Laravel 5.5 和 MySql。如果不向 Services 表中添加 subCategoryID 列,我无法弄清楚如何将类别和子类别与服务相关联。 目前这是我的表结构 服务类别 i
我有两个部分/类别结构的链接表。 the section table structure id sec_title 1 section 1 2 section 2 the category str
我有一个类层次结构如下 @interface PTLDatasource : NSObject ... @interface PTLFetchedDatasource : PTLDatasource
我有一个 DataFrame df 一列,category 使用以下代码创建: import pandas as pd import random as rand from string import
我经常在多个类中设置获取请求以从核心数据(加上一些其他结果)中检索“allRecipes”或“lastModifiedDate”。 为此使用专门的类别 NSManagedObjectContext+R
可以在 Objective C 中创建类别之间的依赖关系吗?也在类别和它们的基类之间? 我知道在运行时应该没有区别,它们可能只是在编译时合并在一起。例如,假设我将 B 类分解为: B(base cla
这个问题在这里已经有了答案: 关闭 10 年前。
example img of a category selection by user 嘿,我正在尝试设置一个选择,用户必须选择一个类别和第二个类别,但我不知道如何获取他单击的信息。用户单击类别后,它
尝试将投资组合库添加到我正在制作的自定义 wp 主题中。我已经筋疲力尽地试图寻找甚至可以修改一些的解决方案和插件。我认为我在寻找解决方案时遇到的一个问题是我不完全确定哪些搜索词可以帮助我找到与我想要实
当我查看 Cocoa Touch API 时,我可以在同一个头文件中找到一些与类别一起声明的类,例如 @interface NSArray : NSObject @property (readonl
我的 log4j.properties 中有以下内容 log4j.rootLogger = debug, stdout, fileLog log4j.appender.stdout = org.apa
如果我在类中添加类别方法,比如NSXMLNode: @interface NSXMLNode (mycat) - (void)myFunc; @end NSXMLNode 的子类,例如 NSXMLEl
先说场景,wordpress的分类结构是这样的 Level 1: Top Level 2: -Nextme_1 Level 3: --Nextme_2 --Nextme_3 Leve
我有一个解析网络,现在我想浏览标签,或显示图表。我怎样才能得到图表?或者在树中导航。显示第一步然后其他等。并了解这棵树是如何 build 的。 import urllib from lxml impo
我是一名优秀的程序员,十分优秀!