Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Collapse Tableview Sections

PixelAddictPixelAddict San FranciscoPosts: 2,022Registered Users @ @ @ @
edited April 2012 in iPhone SDK Development
Hello ,
I have just added the ability to collapse tableview sections in my app and it works great. BUT the issue is when i reload the tableview with a new Google Anlytics Account the functionality no longer works. Take a look at the screen shots and you'll see.
Bad...The section is not showing BUT the header button was pressed...
BadReports2.jpg
Good...This works the first time...
BadReports1.jpg

The sections then show up if i present a modal view and then close it. What is going on?

Thanks.
Post edited by PixelAddict on

Replies

  • brad.gossbrad.goss Posts: 2New Users
    edited February 2010
    Hi Ryan,

    Brad from cocoaminded here. After you've changed the google analytics account, have you tried using

    [tableView reloadData] ?

    It's very difficult to debug your issue without more information. My implementation pretty much assumes <u>static</u> data. How are you managing the state of each section? If you can post your implementation for this method, it may provide some insight.

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  • PixelAddictPixelAddict San FranciscoPosts: 2,022Registered Users @ @ @ @
    edited February 2010
    Hello,
    I have a method to generate the header views and save them into an array in the app delegate
    -(void)generateHeaderViews{
    	bamAnalyticsFullAppDelegate *appDelegatee = [[UIApplication sharedApplication] delegate];
    
    	int sectionHolder = -1;
    	for(NSString *accountName in appDelegatee.accountNames){
    		sectionHolder = sectionHolder + 1;
    		GTHeaderView *hView = [GTHeaderView headerViewWithTitle:accountName Section:sectionHolder];
    		[hView.button addTarget:self action:@selector(toggleSectionForSection:) forControlEvents:UIControlEventTouchUpInside];
    		hView.button.headerSection = sectionHolder;
    		[appDelegatee.headerViews addObject:hView];
    	}
    	[reportsTable reloadData];
    	
    }
    

    I added a BOOL in the Headerview object that tells if its been expanded or not
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    	bamAnalyticsFullAppDelegate *appDelegatee = [[UIApplication sharedApplication] delegate];
    	GTHeaderView *HView = (GTHeaderView *)[appDelegatee.headerViews objectAtIndex:section];
    	
    	//Put the amount of Websites in the Account here
    	int countOfSitesInAccount;
    	
    	if (tableView == self.searchDisplayController.searchResultsTableView)
    	{
            return [self.filteredListContent count];
        }
    	else{
    		
    		if([appDelegatee.groupedAccounts count] == 0){
    			countOfSitesInAccount = 0;
    		}
    		else{
    			NSMutableArray *sitesArray = (NSMutableArray *)[appDelegatee.groupedAccounts objectAtIndex:section];
    			countOfSitesInAccount = [sitesArray count];
    		}
    	}
    	
    	
    	return HView.isExpanded ? countOfSitesInAccount : 0;
    }
    
    
  • brad.gossbrad.goss Posts: 2New Users
    edited February 2010
    Sorry it's been a couple days, been busy.

    It's very tough to debug this scenario. I like that you added the BOOL in the headerview, makes sense. The code you posted appears ok.

    Could you post the method that returns the array of NSIndexPaths? Set a breakpoint there too, and make sure that this method is returning the correct paths when you expand. If the "section" has 3 "rows" in it, then this method should return an array of 3 NSIndexPaths. If it isn't, then there is a problem in this method.
  • PixelAddictPixelAddict San FranciscoPosts: 2,022Registered Users @ @ @ @
    edited February 2010
    it is fine! No worries.
    Here is my code for those functions. I put the breakpoints and NSLogs and the array is returning the correct indexpaths but they do not show up even though it calls the insert rows ...
    - (NSArray*)indexPathsInSection:(NSInteger)section {
    	NSMutableArray *paths = [NSMutableArray array];
    	NSInteger row;
    	
    	for ( row = 0; row < [self numberOfRowsInSection:section]; row++ ) {
    		[paths addObject:[NSIndexPath indexPathForRow:row inSection:section]];
    	}
    	NSLog(@"paths ammount %i", paths.count);
    	return [NSArray arrayWithArray:paths];
    }
    
    - (void)toggle:(BOOL)isExpanded section:(NSInteger)section {
    	bamAnalyticsFullAppDelegate *appDelegatee = [[UIApplication sharedApplication] delegate];
    	GTHeaderView *HView = (GTHeaderView *)[appDelegatee.headerViews objectAtIndex:section];
    	
    	[HView animateArrow:isExpanded view:HView.arrowView];
    	isExpanded = !isExpanded;
    	
    	HView.isExpanded = isExpanded;
    	
    	NSArray *paths = [self indexPathsInSection:section];
    	
    	[self.reportsTable beginUpdates];
    	if ( !isExpanded ){
    		[self.reportsTable deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    	}
    	else{
    		[self.reportsTable insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    
    	}
    	
    	[self.reportsTable endUpdates];
    	[self.reportsTable reloadData];
    }
    
  • PixelAddictPixelAddict San FranciscoPosts: 2,022Registered Users @ @ @ @
    edited February 2010
    This was fixed. The issue was in my code for downloading the reports. I had to create a delegate to tell the childview to reload from the modalview
  • apiphoneapiphone Posts: 140Registered Users
    edited May 2010
    Bertrand21 wrote: »
    This was fixed. The issue was in my code for downloading the reports. I had to create a delegate to tell the childview to reload from the modalview

    Hi Bertrand21,

    Wondering how did you designed the view attached in the original message. I am working on something similar where i would like to expand the table section on selection. I don't know how to add accessory/image to UITableView section.

    Any suggestion

    Thanks
  • PixelAddictPixelAddict San FranciscoPosts: 2,022Registered Users @ @ @ @
    edited June 2010
    apiphone wrote: »
    Hi Bertrand21,

    Wondering how did you designed the view attached in the original message. I am working on something similar where i would like to expand the table section on selection. I don't know how to add accessory/image to UITableView section.

    Any suggestion

    Thanks

    It is just a simple custom UIView. I added a button that shows the state whether it be expanded or not. In my viewdidload I create an instance of the custom view for each table section.
  • CocoaLoverCocoaLover Posts: 1New Users
    edited November 2010
    I've tried various approaches and none seems to give me a smooth expand and smooth table scroll ( without jerking ). What i've tried is modyfing the heightForRowAtIndexPath method and forcing a smooth refresh using the UITableView's beginUpdates/endUpdates methods. Problem with this approach is the fact it requires providing the expanded content for each cell and simply hiding it (using clipping) for the unexpanded cells. This seems unefficient. Another thing i've tried is inserting a new cell at the selectedIndex. Now there's a problem with refreshing the other cells (previously added/expanded). Using a combination of datasource's deleteElementAtIndex and reloadRowsAtIndexPaths gives an unsatisfactory result (unsmooth, hectic animations). Anyone familiar with a way to make an expand like in PASTEBOT ?
  • theinspire29theinspire29 Posts: 1New Users
    edited April 2012
    hi Bertrand21,

    if u dnt mind am not am facing problem with the dynamic Collapse/Expand Table Sections ,so please send some sample code .
Sign In or Register to comment.