我正在使用此代码,但问题是当我点击显示按钮时它没有转换显示,为此再次单击单元格加按钮但我想显示按钮变为显示没有刷新单元格我正在使用此
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (SportsBarWatchAppDelegate *)[[UIApplication sharedApplication] delegate];
logInVc = [[LogInViewController alloc] init];
[self startParsing];
detailTableView = [[UITableView alloc] init];
[detailTableView setBackgroundColor:[UIColor clearColor]];
[detailTableView setShowsHorizontalScrollIndicator:NO];
[detailTableView setShowsVerticalScrollIndicator:NO];
[detailTableView setTag:2];
[detailTableView setHidden:YES];
[detailTableView setDelegate:self];
[detailTableView setDataSource:self];
tableview.separatorColor=[UIColor whiteColor];
editing1 = YES;
expandedSection=-1;
[Searchbar setContentScaleFactor:10.0f];
}
-(void)viewDidAppear:(BOOL)animated
{
[self.navigationController.navigationItem setHidesBackButton:YES];
[self.navigationItem setHidesBackButton:YES];
self.navigationItem.leftBarButtonItem=nil;
self.navigationController.navigationItem.leftBarButtonItem=nil;
UIView *parentView3 = [[UIView alloc] initWithFrame:CGRectMake(25, 0, 200, 40)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, 200, 40)];
label1.backgroundColor = [UIColor clearColor];
label1.textAlignment = UITextAlignmentCenter;
NSString *tempTitleString = [[NSString alloc]
initWithString:appDelegate.bar_Name_String];
label1.text =tempTitleString;
[tempTitleString release];
label1.font = [UIFont fontWithName:@"HelveticaLT-Compressed" size:22];
label1.textColor = [UIColor whiteColor];
[parentView3 addSubview:label1];
parentView3.tag=-10;
[self.navigationController.navigationBar addSubview:parentView3];
UIView *parentView1 = [[UIView alloc] initWithFrame:CGRectMake(2, 6, 70, 35)];
UIButton *backButtn = [[UIButton alloc] initWithFrame:CGRectMake(2, 2, 60, 30)];
[backButtn setBackgroundImage:[UIImage imageNamed:@"back@2x.png"] forState:UIControlStateNormal];
[backButtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[parentView1 addSubview:backButtn];
backButtn.userInteractionEnabled=YES;
backButtn.selected=YES;
parentView1.backgroundColor=[UIColor clearColor];
[backButtn release];
parentView1.tag=-98;
[self.navigationController.navigationBar addSubview:parentView1];
[parentView1 release];
for(UIView* view in self.navigationController.navigationBar.subviews)
{
if(view.tag == -100)
{
[view removeFromSuperview];
}
if(view.tag == -125)
{
[view removeFromSuperview];
}
if(view.tag == -981)
{
[view removeFromSuperview];
}
if(view.tag == -92)
{
[view removeFromSuperview];
}
if(view.tag == -96)
{
[view removeFromSuperview];
}
if(view.tag == -99)
{
[view removeFromSuperview];
}
if(view.tag == -39)
{
[view removeFromSuperview];
}
}
}
-(void)back
{
Req1 *req1VC=[[Req1 alloc]initWithNibName:@"Req1" bundle:nil];
[self.navigationController pushViewController:req1VC animated:NO];
}
-(IBAction)tab_showButtonClicked
{
}
-(void)startParsing
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.labelText = @"Loading...";
[HUD show:YES];
NSString *url = [NSString stringWithFormat:@"http://www.bestbusinessplaces.com/sportzbar/catListXml.php"];
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue cancelAllOperations];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[networkQueue setRequestDidFailSelector: @selector(requestFailed:)];
request= [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setPostValue:appDelegate.barIdString forKey:@"bar_id"];
[request setTimeOutSeconds:60];
[networkQueue addOperation:request];
[networkQueue go];
}
#pragma mark -------------------------
#pragma mark ASIHTTPREQUEST Delegate
- (void)requestFailed:(ASIHTTPRequest *)req
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Failed to Post Item"
message:[[req error] description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorAlert show];
[errorAlert release];
[networkQueue release];
[request release];
[HUD hide:YES];
[HUD removeFromSuperview];
[HUD release], HUD=nil;
}
-(void)requestFinished:(ASIHTTPRequest *)req
{
[networkQueue release];
[request release];
[[Parsing sharedInstance] assignSender:self];
[HUD hide:YES];
[HUD removeFromSuperview];
[HUD release], HUD=nil;
NSMutableArray *resultArray =[[[NSMutableArray alloc]initWithArray:[[Parsing sharedInstance]startparsingforfun:[req responseData]]]autorelease];
NSLog(@"result array %@====>",resultArray);
if ([[[resultArray objectAtIndex:1]objectForKey:@"Transaction"]isEqualToString:@"sportzbar/catListXml"]) {
if ([[[resultArray objectAtIndex:1]objectForKey:@"Success"]isEqualToString:@"True"])
{
if(SportsArray)
{
[SportsArray release];
SportsArray = nil;
}
SportsArray = [[NSMutableArray alloc] init];
if(SportsDetailArray)
{
[SportsDetailArray release];
SportsDetailArray = nil;
}
SportsDetailArray = [[NSMutableArray alloc] init];
for (int k = 2; k < [resultArray count]; k++)
{
if([[resultArray objectAtIndex:k] valueForKey:@"CategoryID"])
{
[SportsArray addObject:[resultArray objectAtIndex:k]];
}
if([[resultArray objectAtIndex:k] valueForKey:@"CatID"])
{
[SportsDetailArray addObject:[resultArray objectAtIndex:k]];
}
}
[tableview reloadData];
}
}
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
CGRect newFrame = CGRectMake(0.0, 0.0, tableView.bounds.size.width, 42);
UIView *headerView = [[[UIView alloc]initWithFrame:newFrame]autorelease];
headerView.backgroundColor=[UIColor grayColor];
headerView.frame = newFrame;
UIImageView *stripImgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 41)];
stripImgView.image=[UIImage imageNamed:@"black-strip.png"];
[headerView addSubview:stripImgView];
[stripImgView release];
UIButton *uploadButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
uploadButton.tag=section;
[uploadButton setBackgroundColor:[UIColor clearColor]];
[uploadButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"add" ofType:@"png"]] forState:UIControlStateNormal];
[uploadButton addTarget:self action:@selector(expandCollapsing:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:uploadButton];
NSString *tableHeader= @"add.png";
switch (sectionID) {
case 0:
tableHeader = hideButton ? @"add.png" : @"green_plusbar@2x.png";
uploadButton.tag = section;
break;
case 1:
tableHeader = hideButton ?@"add.png": @"green_plusbar@2x.png" ;
uploadButton.tag = section;
break;
case 2:
tableHeader = hideButton ? @"add.png" : @"green_plusbar@2x.png";
uploadButton.tag = section;
break;
default:
break;
}
[[uploadButton viewWithTag:sectionID] setImage:[UIImage imageNamed:tableHeader] forState:UIControlStateNormal];
UILabel *locationLabel = [[UILabel alloc]init];
[locationLabel setFrame:CGRectMake(10, 0, 300,30 )];
locationLabel.tag=2;
locationLabel.textColor = [UIColor whiteColor];
locationLabel.backgroundColor=[UIColor clearColor];
locationLabel.text=[[SportsArray objectAtIndex:section] valueForKey:@"MatchTitle"];
locationLabel.numberOfLines=8;
locationLabel.adjustsFontSizeToFitWidth=YES;
[locationLabel setLineBreakMode:UILineBreakModeCharacterWrap];
[locationLabel release];
UIButton*ImageButton=[[UIButton alloc]initWithFrame:CGRectMake(4,2,42,40)];
[ImageButton setUserInteractionEnabled:NO];
[ImageButton setBackgroundColor:[UIColor clearColor]];
NSString *ImagePath =[NSString stringWithFormat:@"%@",[[SportsArray objectAtIndex:section]valueForKey:@"CategoryLogo"]];
[ImageButton setImageWithURL:[NSURL URLWithString:ImagePath]
placeholderImage:[UIImage imageNamed:@"Transparent@2x.png"]];
[headerView addSubview:ImageButton];
UILabel *NameLabelTitle=[[UILabel alloc]initWithFrame:CGRectMake(60,5,150,30)];
[NameLabelTitle setText:[[SportsArray objectAtIndex:section] valueForKey:@"CategoryName"]];
[NameLabelTitle setBackgroundColor:[UIColor clearColor]];
[NameLabelTitle setTextColor:[UIColor whiteColor]];
[NameLabelTitle setFont:[UIFont fontWithName:@"HelveticaLT-Compressed" size:20]];
[headerView addSubview:NameLabelTitle];
UIButton *Close_Button=[[UIButton alloc]initWithFrame:CGRectMake(270,7,25,25)];
[Close_Button setTag:section];
[Close_Button setImage:[UIImage imageNamed:@"add.png"]forState:UIControlStateNormal];
if (section==expandedSection) {
[Close_Button setImage:[UIImage imageNamed:@"removeBtn.png"]forState:UIControlStateNormal];
}
else {
[Close_Button setImage:[UIImage imageNamed:@"add.png"]forState:UIControlStateNormal];
}
[Close_Button setUserInteractionEnabled:YES];
[Close_Button addTarget:self action:@selector(expandSection:) forControlEvents:UIControlEventTouchUpInside];
[Close_Button setBackgroundColor:[UIColor clearColor]];
[headerView addSubview:Close_Button];
UILabel *lineOnly=[[UILabel alloc]initWithFrame:CGRectMake(3,58,315,.7f)];
[lineOnly setBackgroundColor:[UIColor whiteColor]];
[lineOnly setTextColor:[UIColor whiteColor]];
[lineOnly release];
return headerView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
NSLog(@"section count is %d",[SportsArray count]);
return [SportsArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 43;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return 100.0f;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIndentifier=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIndentifier];
if(cell ==nil)
{
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
UIView *subview;
while ((subview= [[[cell contentView]subviews]lastObject])!=nil)
[subview removeFromSuperview];
}
Close_Open_Button=[[UIButton alloc]initWithFrame:CGRectMake(260,10,56,23)];
[Close_Open_Button setTag:indexPath.row];
[Close_Open_Button setUserInteractionEnabled:YES];
[Close_Open_Button addTarget:self action:@selector(showButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
if([[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"ShowingOrNot"] isEqualToString:@"Show"])
{
checkShow=1;
[Close_Open_Button setImage:[UIImage imageNamed:@"showButton@2x.png"]forState:UIControlStateNormal];
[detailTableView reloadData];
}
else
{
checkShow=2;
[Close_Open_Button setImage:[UIImage imageNamed:@"showing.png"]forState:UIControlStateNormal];
[detailTableView reloadData];
}
[Close_Open_Button setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:Close_Open_Button];
UIButton *facebook_Button=[[UIButton alloc]initWithFrame:CGRectMake(267,60,21,21)];
[facebook_Button setTag:indexPath.row];
[facebook_Button setImage:[UIImage imageNamed:@"face@2x.png"]forState:UIControlStateNormal];
[facebook_Button setUserInteractionEnabled:YES];
[facebook_Button addTarget:self action:@selector(fbButton1:) forControlEvents:UIControlEventTouchUpInside];
[facebook_Button setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:facebook_Button];
UIButton *twitter_Button=[[UIButton alloc]initWithFrame:CGRectMake(289,60,21,21)];
[twitter_Button setTag:indexPath.row];
[twitter_Button setImage:[UIImage imageNamed:@"twitt@2x.png"]forState:UIControlStateNormal];
[twitter_Button setUserInteractionEnabled:YES];
[twitter_Button addTarget:self action:@selector(twButton1:) forControlEvents:UIControlEventTouchUpInside];
[twitter_Button setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:twitter_Button];
UILabel *dateLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,8,200,20)];
[dateLabel setText:[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"MatchDate"]];
[dateLabel setBackgroundColor:[UIColor clearColor]];
dateLabel.font=[UIFont systemFontOfSize:12];
[dateLabel setTextColor:[UIColor colorWithRed:255/255.0f green:216/255.0f blue:0/255.0f alpha:1.0]];
[cell.contentView addSubview:dateLabel];
[dateLabel release];
UILabel *NameLabel1=[[UILabel alloc]initWithFrame:CGRectMake(10,20,255,30)];
[NameLabel1 setText:[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"MatchTitle"]];
[NameLabel1 setBackgroundColor:[UIColor clearColor]];
[NameLabel1 setTextColor:[UIColor whiteColor]];
[NameLabel1 setFont:[UIFont boldSystemFontOfSize:15.0f]];
[cell.contentView addSubview:NameLabel1];
[NameLabel1 release];
UILabel *subCategoryLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,35,255,30)];
[subCategoryLabel setText:[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"SubCategory"]];
[subCategoryLabel setBackgroundColor:[UIColor clearColor]];
[subCategoryLabel setTextColor:[UIColor whiteColor]];
[subCategoryLabel setFont:[UIFont systemFontOfSize:10.0f]];
[cell.contentView addSubview:subCategoryLabel];
[subCategoryLabel release];
UILabel *timeLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,50,200,38)];
[timeLabel setText:[NSString stringWithFormat:@"%@ (Local Time)",[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"Time"]]];
[timeLabel setBackgroundColor:[UIColor clearColor]];
[timeLabel setTextColor:[UIColor whiteColor]];
timeLabel.font=[UIFont systemFontOfSize:11];
[cell.contentView addSubview:timeLabel];
[timeLabel release];
UILabel *GuestLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,70,60,30)];
[GuestLabel setText:[NSString stringWithFormat:@"%@ people",[[subDetailArray objectAtIndex:indexPath.row] valueForKey:@"Guests"]]];
[GuestLabel setBackgroundColor:[UIColor clearColor]];
[GuestLabel setTextColor:[UIColor colorWithRed:255/255.0f green:216/255.0f blue:0/255.0f alpha:1.0]];
[GuestLabel setFont:[UIFont italicSystemFontOfSize:10.0f]];
[cell.contentView addSubview:GuestLabel];
[GuestLabel release];
UILabel *GuestLabel1=[[UILabel alloc]initWithFrame:CGRectMake(60,70,200,30)];
[GuestLabel1 setText:[NSString stringWithString:@"have registered Interest"]];
[GuestLabel1 setBackgroundColor:[UIColor clearColor]];
[GuestLabel1 setTextColor:[UIColor whiteColor]];
[GuestLabel1 setFont:[UIFont italicSystemFontOfSize:10.0f]];
[cell.contentView addSubview:GuestLabel1];
[GuestLabel1 release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(185, 47, 150, 50)];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
[label setFont:[UIFont italicSystemFontOfSize:9.5f]];
label.text = @"Share with Friends";
[cell.contentView addSubview:label];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor colorWithRed:53/255.0f green:53/255.0f blue:53/255.0f alpha:1.0];
[self.view addSubview:tableview];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int numberOfRows = [subDetailArray count];
if(self.editing) numberOfRows++;
if (section==expandedSection) {
return numberOfRows;
}
else {
return 0;
}
}
- (void) expandSection:(id)sender {
int tag=((UIButton*)sender).tag;
if(subDetailArray)
{
[subDetailArray release];
subDetailArray = nil;
}
subDetailArray = [[NSMutableArray alloc] init];
for(NSMutableDictionary *dict in SportsDetailArray)
{
if([[[SportsArray objectAtIndex:tag] valueForKey:@"CategoryID"] isEqualToString:[dict objectForKey:@"CatID"]])
{
[subDetailArray addObject:dict];
}
}
[tableview reloadData];
if (expandedSection == [sender tag]) {
expandedSection = -1;
[tableview reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationFade];
}else if (expandedSection == -1){
expandedSection = [sender tag];
[tableview reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationFade];
}else{
[tableview beginUpdates];
[tableview reloadSections:[NSIndexSet indexSetWithIndex:expandedSection] withRowAnimation:UITableViewRowAnimationFade];
expandedSection = [sender tag];
[tableview reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationFade];
[tableview endUpdates];
}
[tableview reloadData];
}
- (void)checkAction:(id)sender
{
UIButton *Button = (UIButton*)sender;
if([[subDetailArray objectAtIndex:Button.tag] isEqualToString:@"UP"])
{
[subDetailArray replaceObjectAtIndex:Button.tag withObject:@"DOWN"];
}
else
{
[subDetailArray replaceObjectAtIndex:Button.tag withObject:@"UP"];
}
[tableview reloadSections:[NSIndexSet indexSetWithIndex:Button.tag] withRowAnimation:UITableViewRowAnimationFade];
}
-(void)expandCollapsing :(id)sender
{
int tag=((UIButton*)sender).tag;
if(subDetailArray)
{
[subDetailArray release];
subDetailArray = nil;
}
subDetailArray = [[NSMutableArray alloc] init];
for(NSMutableDictionary *dict in SportsDetailArray)
{
if([[[SportsArray objectAtIndex:tag] valueForKey:@"CategoryID"] isEqualToString:[dict objectForKey:@"CatID"]])
{
[subDetailArray addObject:dict];
}
}
NSIndexPath *indexPath =[tableview indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
row1 = indexPath.row;
sectionID = ((UIButton *)sender).tag;
UITableViewCell *cell = [tableview cellForRowAtIndexPath:indexPath];
[cell setAutoresizesSubviews:YES];
if (count==0) {
{
NSInteger RowsDelete = [tableview numberOfRowsInSection:sectionID];
if(RowsDelete>1){
[self deleteSectionRows:sectionID];
sectionHidden=NO;
}
else {
[self updateSection];
row1+=1;
self.indexPaths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:row1 inSection:sectionID],nil];
count=1;
}
}
else
{
NSLog(@"productsArray is %@",SportsArray);
NSInteger RowsToDelete = [tableview numberOfRowsInSection:sectionID];
if (RowsToDelete<1) {
[self updateSection];
}
else {
NSLog(@"row in delete is %d",row1);
hideButton=FALSE;
[self deleteSectionRows:sectionID];
}
checkButtonClick=sectionID;
}
-(void)updateSection
{
NSMutableArray *indexPathToInsert=[[NSMutableArray alloc]init];
for (int i=0; i<[[subDetailArray valueForKey:@"CategoryID"]count]; i++) {
[indexPathToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionID]];
}
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
NSInteger previousOpenSectionIndex = self.openSectionIndex;
if (previousOpenSectionIndex != NSNotFound) {
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
}
}
UITableViewRowAnimation deleteAnimation;
if (previousOpenSectionIndex == NSNotFound ) {
countOfRowsToDelete = [[subDetailArray valueForKey:@"CategoryID"]count];
NSLog(@"count to del %d",countOfRowsToDelete);
sectionHidden=YES;
}
else {
deleteAnimation = UITableViewRowAnimationTop;
countOfRowsToDelete = [[subDetailArray valueForKey:@"CategoryID"]count];
sectionHidden=NO;
}
[tableview beginUpdates];
[tableview insertRowsAtIndexPaths:indexPathToInsert
withRowAnimation:UITableViewRowAnimationFade];
[tableview deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
[tableview endUpdates];
[tableview scrollToRowAtIndexPath:[indexPathToInsert objectAtIndex:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
[indexPathToInsert release];
[indexPathsToDelete release];
[tableview setNeedsDisplay];
}
-(void)deleteSectionRows:(NSInteger)sectionClosed
{
NSLog(@"section is %d",sectionClosed);
sectionHidden=NO;
count=0;
NSInteger RowsToDelete = [tableview numberOfRowsInSection:sectionClosed];
if (RowsToDelete > 0) {
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < RowsToDelete; i++)
{
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
}
[tableview deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
[indexPathsToDelete release];
}
self.openSectionIndex = NSNotFound;
[tableview reloadData];
}