如何在ios中单击特定标题时显示可扩展列表
我只想在单击标题部分“2”时显示可展开列表。为此,我从一些地方编辑了这段代码 这里我的主要要求是,当我单击标题部分“2”时,我想加载我自己的数组列表数据,比如(当我单击标题部分2时,arrayforpool=“hai”、“how”、“fine”数据)如何在ios中单击特定标题时显示可扩展列表,ios,objective-c,Ios,Objective C,我只想在单击标题部分“2”时显示可展开列表。为此,我从一些地方编辑了这段代码 这里我的主要要求是,当我单击标题部分“2”时,我想加载我自己的数组列表数据,比如(当我单击标题部分2时,arrayforpool=“hai”、“how”、“fine”数据) #导入“ShowList.h” #导入“MFSideMenu.h” #导入“ViewController.h” @接口显示列表(){ NSString*imgUrlStr; UIImageView*imgNew; UILabel*usrNameLb
#导入“ShowList.h”
#导入“MFSideMenu.h”
#导入“ViewController.h”
@接口显示列表(){
NSString*imgUrlStr;
UIImageView*imgNew;
UILabel*usrNameLbl;
NSString*usrName;
UIViewController*demoViewController;
UIColor*bg_颜色;
NSMUTABLEARRY*imageArr;
布尔是第一次跑步;
UIImageView*用户图像;
NSMutableArray*arrayforpool;
NSArray*截面标题雷;
NSArray*子列表;
}
@结束
@实现展示列表
@合成myTab;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
arrayForBool=[[NSMutableArray alloc]init];
sectionTitleArray=[[NSMUTABLEARRY alloc]init];
self.view.backgroundColor=[UIColor grayColor];
self.myTab.backgroundColor=bg_color;
self.myTab.delegate=self;
self.myTab.dataSource=self;
self.myTab.scrollEnabled=是;
myTab.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHight;
[自我初始化];
}
-(无效)初始化
{
sectionTitleArray=[[NSArray alloc]initWithObjects:
@“拉朱”,
@“草莓”,
@“葡萄”,
@“橙色”,
@“香蕉”,
@“木瓜”,
@“番石榴”,
@“菠萝”,
零];
对于(int i=0;i根据您获得的异常数组索引边界异常请修改我的代码并发布该代码,然后减少我的pain@m.v.n.kalyani-它是立即崩溃还是当你点击标题2时崩溃?在你的问题中包含完整的错误。我实际上已经编辑了5段代码,我不知道如何修改它根据我的要求,当我们单击标题“2”时,我希望在可扩展列表中加载我的arrayForboll dat我已经编辑了这段代码,请帮助我发布你得到的异常数组索引边界异常请修改我的代码并发布,然后减少我的pain@m.v.n.kalyani-它是立即崩溃还是当你点击标题2时崩溃?在你的问题中包含完整的错误。我实际上从一些我不理解的地方编辑了5这段代码如何根据我的要求修改此代码,并在单击标题“2”时在可展开列表中加载我的arrayForboll dat。我已编辑此代码,请帮助我
#import "ShowList.h"
#import "MFSideMenu.h"
#import "ViewController.h"
@interface ShowList (){
NSString *imgUrlStr;
UIImageView *imgNew ;
UILabel *usrNameLbl;
NSString *usrName;
UIViewController *demoViewController;
UIColor *bg_color;
NSMutableArray *imageArr;
BOOL isfirstTimeRun;
UIImageView * userimage;
NSMutableArray *arrayForBool;
NSArray *sectionTitleArray;
NSArray * sublist;
}
@end
@implementation ShowList
@synthesize myTab;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrayForBool = [[NSMutableArray alloc]init];
sectionTitleArray = [[NSMutableArray alloc]init];
self.view.backgroundColor = [UIColor grayColor];
self.myTab.backgroundColor = bg_color;
self.myTab.delegate = self;
self.myTab.dataSource = self;
self.myTab.scrollEnabled = YES;
myTab.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self initialization];
}
-(void)initialization
{
sectionTitleArray=[[NSArray alloc]initWithObjects:
@"Raju",
@"Strawberry",
@"Grapes",
@"Orange",
@"Banana",
@"Papaya",
@"Guava",
@"pineapple",
nil];
for (int i=0; i<[sectionTitleArray count]; i++) {
[arrayForBool addObject:[NSNumber numberWithBool:NO]];
}
}
#pragma mark -
#pragma mark TableView DataSource and Delegate Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[arrayForBool objectAtIndex:section] boolValue]) {
return section+2;
}
else
return 0;
return arrayForBool.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellid=@"hello";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
}
BOOL manyCells = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
/********** If the section supposed to be closed *******************/
if(!manyCells)
{
cell.backgroundColor=[UIColor clearColor];
cell.textLabel.text=@"";
}
/********** If the section supposed to be Opened *******************/
else
{
cell.textLabel.text=[NSString stringWithFormat:@" %@ %d",[sectionTitleArray objectAtIndex:indexPath.section],indexPath.row+1];
cell.textLabel.font=[UIFont systemFontOfSize:15.0f];
cell.backgroundColor=[UIColor whiteColor];
cell.imageView.image=[UIImage imageNamed:@"point.png"];
cell.selectionStyle=UITableViewCellSelectionStyleNone ;
}
cell.textLabel.textColor=[UIColor blackColor];
/********** Add a custom Separator with cell *******************/
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(40, 40, myTab.frame.size.width, 1)];
separatorLineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:separatorLineView];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [sectionTitleArray count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[arrayForBool replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:NO]];
[myTab reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[arrayForBool objectAtIndex:indexPath.section] boolValue]) {
return 40;
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 40;
}
#pragma mark - Creating View for TableView Section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 280,40)];
sectionView.tag=section;
UILabel *viewLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, myTab.frame.size.width-10, 40)];
viewLabel.backgroundColor=[UIColor clearColor];
viewLabel.textColor=[UIColor blackColor];
viewLabel.font=[UIFont systemFontOfSize:15];
viewLabel.text=[NSString stringWithFormat:@"%@",[sectionTitleArray objectAtIndex:section]];
[sectionView addSubview:viewLabel];
/********** Add a custom Separator with Section view *******************/
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, myTab.frame.size.width, 1)];
separatorLineView.backgroundColor = [UIColor blackColor];
[sectionView addSubview:separatorLineView];
/********** Add UITapGestureRecognizer to SectionView **************/
UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
[sectionView addGestureRecognizer:headerTapped];
return sectionView;
}
#pragma mark - Table header gesture tapped
- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:gestureRecognizer.view.tag];
BOOL collapsed = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
if (indexPath.section==1) {
[arrayForBool replaceObjectAtIndex:1 withObject:[NSNumber numberWithBool:!collapsed]];
}
[myTab reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end