Multiple Table Cells?

Discussion in 'iOS Development' started by Spreche, Jul 29, 2008.

  1. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    I have a question about making tables for an application of mine. How would I go about making cells for each individual column. Does it have to do anything with NSArray or NSDictionary? I was researching for answers on the ADC but they use code very vaguely.

    I got an idea of how this works, but don't quite know how to implement it. Here is an image from where I got my information.

    Please Register or Log in to view images

    Attached Files:

  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    check out http://gojohnnyboi.googlecode.com/svn/trunk

    and look at gLauncher's code. It uses a standard UITable like that one. Also, to add the arrow to the cell you would use this code:

    Code:
    [ cell setDisclosureStyle: 1 ]; // this goes i think from 0-3 maybe 0-2
    [ cell setShowDisclosure: TRUE ]; // tell the cell to show the arrow
  3. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    Yeah that's what I based my table off of was your gLauncher code. I edited the code so it wasn't a 'launcher' and just a table. But when I add a cell it gives me the same cell for each cell that is displayed.

    This is how I edited it:
    Code:
    #import "PurchaseFromList.h"
    //#import <UIKit2/UIColor.h>
    #import <WebCore/WebFontCache.h>
    #import <GraphicsServices/GraphicsServices.h>
    #import <UIKit/UITableCellDisclosureView.h>
    #import <UIKit/UISimpleTableCell.h>
    
    @implementation PurchaseFromList 
    
    
    - (id)initWithFrame:(CGRect)rect
    {
    	if(( self == [ super initWithFrame: rect ]) != nil)
    		{
    			UITableColumn* tableColumn = [ [ UITableColumn alloc] initWithTitle:@"iShop" identifier:@"column1" width:rect.size.width ];
    			[ self addTableColumn: tableColumn ];
    			
    			[ self setDelegate: self ];
    			[ self setDataSource: self ];
    			[ self setSeparatorStyle: 1 ];
    			[ self setRowHeight: 65 ];
    		}
    	return self;
    }
    
    - (int)numberOfRowsInTable:(UITable*)table
    {	
    	int i = 8;
    	return i;
    }
    
    - (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)column
    {	
    		
    	UISimpleTableCell* cell = [ [ [ UISimpleTableCell alloc ] init] autorelease ];
    	[cell setTitle:@"Grocery Stores"];
    	[cell setShowDisclosure: YES];
    	[cell setDisclosureStyle: 0];
    	
    	return [cell autorelease];
    }
    
    
    - (void)dealloc
    {
    	[ appManager release ];
    	[ appArray release ];
    	[ infoArray release ];
    	[ super dealloc ];
    }
    
    - (void)tableRowSelected:(NSNotification*)notification
    {
    	[[[notification object]cellAtRow:[[notification object]selectedRow]column:0] setSelected:FALSE withFade:TRUE];
    	[ UIApp launchApplicationWithIdentifier: [ infoArray objectAtIndex: [ self selectedRow ] ] suspended: NO ];
    }
    
    @end
    
    And the output is this:

    Please Register or Log in to view images

  4. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I don't understand the problem in what you're doing
  5. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    Okay, I'll address this as clear as possible. I have a table that is 1 column, and has 8 rows. When I create a cell for a row, I only want it to occupy one row. Instead what it is doing is occupying all 8 of my rows. My goal is to have those 8 rows display different items(Grocery Stores; Retail Stores; Online Stores). But what it is doing is displaying the same thing for all 8 rows.
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    try usign an if statement

    Code:
    if(row == 1)
    {
    UITableCell*.....
    return ...
    }
    if(row == 2)
    UITableCell*...
    return...
    }
  7. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    It crashes when I open it. Is it because I have no return for the whole function?

    Code:
    - (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)column
    {	
    	if(row == 1)
    	{	
    		UISimpleTableCell* cell1 = [ [ UISimpleTableCell alloc ] init];
    		[cell1 setTitle:@"Retail Stores"];
    		[cell1 setShowDisclosure: YES];
    		[cell1 setDisclosureStyle: 0];
    		return cell1;
    	}
    	if(row == 2)
    	{	
    		UISimpleTableCell* cell2 = [ [ UISimpleTableCell alloc ] init];
    		[cell2 setTitle:@"Online Stores"];
    		[cell2 setShowDisclosure: YES];
    		[cell2 setDisclosureStyle: 0];
    		return cell2;
    	}
    }
    
  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    change your return value for rowsingroup, you still have it set to 8, so its looking for 8, and you're only giving it 2
  9. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    Okay, I changed everything. Now I have 5 rows and 5 cells. But it still crashes. Do you mean numberOfRowsInTable when you said rowsInGroup?

    Code:
    - (int)numberOfRowsInTable:(UITable*)table
    {	
    	int i = 5;
    	return i;
    }
    
    - (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)column
    {	
    
    	if(row == 1)
    	{	
    		UISimpleTableCell* cell1 = [ [ UISimpleTableCell alloc ] init];
    		[cell1 setTitle:@"Retail Stores"];
    		[cell1 setShowDisclosure: YES];
    		[cell1 setDisclosureStyle: 0];
    		return cell1;
    	}
    	if(row == 2)
    	{	
    		UISimpleTableCell* cell2 = [ [ UISimpleTableCell alloc ] init];
    		[cell2 setTitle:@"Online Stores"];
    		[cell2 setShowDisclosure: YES];
    		[cell2 setDisclosureStyle: 0];
    		return cell2;
    	}
    	if(row == 3)
    	{	
    		UISimpleTableCell* cell3 = [ [ UISimpleTableCell alloc ] init];
    		[cell3 setTitle:@"Local Stores"];
    		[cell3 setShowDisclosure: YES];
    		[cell3 setDisclosureStyle: 0];
    		return cell3;
    	}
    	if(row == 4)
    	{	
    		UISimpleTableCell* cell4 = [ [ UISimpleTableCell alloc ] init];
    		[cell4 setTitle:@"Manufacturers"];
    		[cell4 setShowDisclosure: YES];
    		[cell4 setDisclosureStyle: 0];
    		return cell4;
    	}
    	if(row == 5)
    	{	
    		UISimpleTableCell* cell5 = [ [ UISimpleTableCell alloc ] init];
    		[cell5 setTitle:@"Local Stores"];
    		[cell5 setShowDisclosure: YES];
    		[cell5 setDisclosureStyle: 0];
    		return cell5;
    	}
    	
    }
    
  10. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    i think you may have to start with row 0, not row 1. try that

Share This Page