indexed list on left side of tableview

Discussion in 'iOS Programming' started by AbhishekApple, Nov 8, 2010.

  1. AbhishekApple macrumors member

    Joined:
    Aug 5, 2010
    #1
    Is the following thing possible...
    indexed list on left side....(AA,AB,AC,AD......)

    [​IMG]
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Possible? I suspect that it could be done using a custom view that you write yourself, resizing the table view to allow space for it and writing code to supply a datasource to it and a load of glue code to interact with the table.
     
  3. AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010
    #3
    Thanks for that quick reply...
    can i find some help in apples site with the normal indexed list creation
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I doubt it. For the normal index you just have to supply a list a character for each section and Apple's code (which you can't see) does all the work. If you want an odd interface like that you are basically on your own.
     
  5. AbhishekApple, Nov 9, 2010
    Last edited: Nov 9, 2010

    AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010
    #5
    I have used another idea to execute the functionality..
    => on click of the indexed list (A,B,C,D....) the indexed list will be regenerated with new value i.e AA,AB,AC,AD....
    => and when the user clicks the refresh button (on navigation bar) again original indexed list will be generated (A,B,C,D....)

    Now i am stuck with following thing,
    =>the following code executes perfectly for the first time but it gives EXC_Bad_access...(their are no leaks, i have checked)

    error is thrown on the following line marked red
    and i doubt on char conversion marked orange

    but it works when the table loads for first time but crashes when reloads...
    Code:
    //dblIndex is used for AA,AB,Ac series and else part for A,B,C..
    
    NSSTring *sortVal;
    
    - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    	
    	if(searching)
    		return -1;
    	else if(dblIndex) {
    		return index;
    	}
    	else {
    		dblIndex=YES;
    		sortVal=nil;
    		//unichar c = index+65;
    		//sortVal = (NSString*)c;
    		[COLOR="DarkOrange"]sortVal=[NSString stringWithFormat:@"%c",index+65];[/COLOR]
    		[Dictionary arrySortContactsRemoveAll];
    		[Dictionary showSortContacts:sortVal];
    		[tblView reloadData];
    		return 0;
    	}
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    	
    	if(searching)
    		return @"Search Result";
    	else if(dblIndex){
    		
    			NSLog(@"%d",section);
    		NSArray *dblary =[[Dictionary getarrySortContacts] objectAtIndex:section];
    		if ([dblary count]==0) {
    			return nil;
    		}
    		
         [B][COLOR="red"]NSLog(@"%@",sortVal);[/COLOR][/B]
    	return [NSString stringWithFormat:@"%c",section+65];
    	
    	
    	}
    	else {
    		NSArray *ary =[[Dictionary getarryContacts] objectAtIndex:section];
    		//NSLog(@"%d",section);
    		if ([ary count]==0) {
    			return nil;
    		}
    			
    		return [NSString stringWithFormat:@"%c",section+65];
    	}
    }
    
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    I suggest you need to read the basic Memory Management Guide on the developer site. You clearly do not know when a method is returning an autoreleased object and when it isn't (hint your Orange line is returning an autoreleased object that you are not retaining so when you try and access this later it no longer exists: basic schoolboy error).

    Oh and please don't PM me asking me to help you: I'll decide where and when to post thank you.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    EXC_BAD_ACCESS is caused by the exact opposite of memory leaks.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    Running your program with zombies enabled will find most of these under-retain or over-release errors.

    http://meandmark.com/blog/2010/09/using-nszombie-with-instruments/
    http://www.cocoadev.com/index.pl?NSZombieEnabled
    http://www.corbinstreehouse.com/blo...debug-those-random-crashes-in-your-cocoa-app/
    http://www.iphonedevsdk.com/forum/iphone-sdk-development/9781-trouble-setting-nszombieenabled.html

    Everyone should run their program with zombies enabled at least once a week.
    This does two things:
    1. It alerts you to any hidden under-retain problems before they cause a crash.
    2. It teaches you how to use the feature, so when you need it (and you inevitably will) you already know how to use it.
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Just don't forget to turn off zombies-enabled before you build for distribution! ;)
     
  10. AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010

Share This Page