0
我在每個部分有四個部分有五個行。當點擊任何行時它顯示實際數據時再次點擊它顯示另一個部分data.i無法理解我錯在哪裏Section重複數據在另一行。這裏是我的代碼和圖像。在其他部分點擊時段單元格重複
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section==0) {
return 5;
}
if (section==1) {
return 5;
}
if (section==2) {
return 5;
}
if (section==3) {
return 5;
}
return 5;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
headerView.tag = section;
headerView.backgroundColor = [UIColor lightTextColor];
UILabel *headerString= [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.frame.size.width-20-50,50)];
BOOL manyCells = [[boolenarry objectAtIndex:section] boolValue];
if (!manyCells) {
headerString.text =self.Titlearray[section]
}else{
headerString.text =self.Titlearray[section];
}
headerString.textAlignment = NSTextAlignmentLeft;
headerString.textColor = [UIColor whiteColor];
[headerView addSubview:headerString];
UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
[headerView addGestureRecognizer:headerTapped];
return headerView;
}
- (UIView *)tableView:(UITableView *)tableView
viewForFooterInSection:(NSInteger)section{
UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
return footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([[boolenarry objectAtIndex:indexPath.section] boolValue]) {
return 50;
}
return 0;
}
- (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];
if ([[UIDevice currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
}
}
BOOL manyCells = [[boolenarry objectAtIndex:indexPath.section]
boolValue];
if (!manyCells) {
NSDate *object = self.Titlearray[indexPath.section];
cell.textLabel.text = [object description];
}
else{
NSArray *content = [recipes valueForKey:[Titlearray
objectAtIndex:indexPath.section]];
cell.textLabel.text = [content objectAtIndex:indexPath.row];
}
if (indexPath.section==0) {
allindgre= [recipes objectForKey:@"Ingrdent"];
preparetime=[recipes objectForKey:@"preparetimeing"];
makingarray=[recipes objectForKey:@"makingsample"];
imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage
imageNamed:@"chickengravy1.jpg"],[UIImage
imageNamed:@"Crispychicken.jpg"],[UIImage
imageNamed:@"ButtermilkChk.jpg"],
[UIImage imageNamed:@"southernchik.jpg"],
[UIImage imageNamed:@"SimpleChicken.jpg"],nil];
if (indexPath.row==0) {
cell.imageView.image= [UIImage imageNamed:@"Res Images
/chicken grav.jpg"];
}
else if (indexPath.row==1) {
cell.imageView.image= [UIImage imageNamed:@"Res Images
/crispy chicken.jpg"];
}
else if (indexPath.row==2) {
cell.imageView.image= [UIImage imageNamed:@"Res Images
/Buttermilk Chicken.jpg"];
}
else if (indexPath.row==3) {
cell.imageView.image= [UIImage imageNamed:@"Res Images
/Southern Chicke.jpg"];
}
else if (indexPath.row==4) {
cell.imageView.image= [UIImage imageNamed:@"Res Images
/Simple Chick.jpg"];
}}
if (indexPath.section==1) {
allindgre=[recipes objectForKey:@"ricerecipes"];
preparetime=[recipes objectForKey:@"ricepreparetimeing"];
makingarray=[recipes objectForKey:@"ricemakingsample"];
imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage
imageNamed:@"Tofu Fried.jpg"],[UIImage imageNamed:@"chicken fried
rice.jpg"],[UIImage imageNamed:@"sweet-soy.jpg"],
[UIImage imageNamed:@"Southeast Asian.jpg"],
[UIImage imageNamed:@"Spicy Vegetable.jpg"],nil];
if (indexPath.section==2)
{
allindgre=[recipes objectForKey:@"burgerrecipes"];
preparetime=[recipes objectForKey:@"bugerpreparetimeing"];
makingarray=[recipes objectForKey:@"bmakingrecipes"];
imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage
imageNamed:@"burger/blue burger.jpg"],[UIImage
imageNamed:@"burger/serrano pepper.jpg"],[UIImage
imageNamed:@"burger/smak bloody mary.jpg"],
[UIImage imageNamed:@"burger/italian style
meatball.jpg"],
[UIImage imageNamed:@"burger/Gold Nugget
Burger.jpg"],nil];
if (indexPath.row==0) {
UIImage *omeltte=[UIImage imageNamed:@"Images/buger.png"];
cell.imageView.image = omeltte;
}
}
if (indexPath.section==3)
{
allindgre=[recipes objectForKey:@"pizzarecipes"];
preparetime=[recipes objectForKey:@"pizzapreparetimeing"];
makingarray=[recipes objectForKey:@"pmakingrecipes"];
imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"burger/Garlic Chicken Pizza.jpg"],[UIImage imageNamed:@"burger/Pizza On The Grillr.jpg"],[UIImage imageNamed:@"burger/BBQ Chicken Pizza.jpg"],
[UIImage imageNamed:@"burger/Veggie Pizza.jpg"],
[UIImage imageNamed:@"burger/Four Cheese Margherita Pizza.jpg"],nil];
if (indexPath.row==0) {
UIImage *pizza=[UIImage imageNamed:@"Images/pizza.png"];
cell.imageView.image = pizza;
}
}
[[cell contentView] setBackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
[[cell textLabel]setTextColor:[UIColor blackColor]];
UIImage *background = [self cellBackgroundForRowAtIndexPath :indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
return cell;
}
#pragma mark - gesture tapped
- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag];
if (indexPath.row==0) {
BOOL collapsed = [[boolenarry objectAtIndex:indexPath.section] boolValue];
collapsed = !collapsed;
[boolenarry replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:collapsed]];
}
//reload specific section animated
NSRange range = NSMakeRange(indexPath.section,1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationFade];
}
#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:
(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView
indexPathForSelectedRow];
DetailViewController *destViewController=
segue.destinationViewController;
destViewController.detailItem = [[recipes objectForKey:
[Titlearray objectAtIndex:indexPath.section ]]
objectAtIndex:indexPath.row];
NSString*allrec= [allindgre objectAtIndex:indexPath.row];
[[segue destinationViewController]setPtext:allrec];
NSString*preparetim =[preparetime objectAtIndex:indexPath.row];
[[segue destinationViewController] setPretime:preparetim];
NSString*make=[makingarray objectAtIndex:indexPath.row];
[[segue destinationViewController]setMethetext:make];
UIImage*imagestring=[imagearray objectAtIndex:indexPath.row];
[[segue destinationViewController] setImagess:imagestring];
}}
你能告訴我們一些代碼嗎? – Mahesh
我添加了我的整個代碼 –
哪些數據正在重複?單元格或標題?你可以顯示你的didselect行方法嗎? – Mahesh