cant populate cells with an array when i have loaded a second UITableViewController

Posted by richard Stephenson on Stack Overflow See other posts from Stack Overflow or by richard Stephenson
Published on 2010-04-01T15:41:06Z Indexed on 2010/04/01 15:43 UTC
Read the original article Hit count: 305

Filed under:
|
|

hi there, im very new to iphone programming, im creating my first app, (a world cup one) the first view is a table view. the cell text label is filled with an array, so it shows all the groups (group a, B, c,ect) then when you select a group, it pulls on another UITableViewcontroller, but whatever i do i cant set the text label of the cells (e.g france,mexico,south africa, etc. infact nothin i do to the cellForRowAtIndexPath makes a difference , could someone tell me what im doing wrong please

Thanks

`here is my code for the view controller

    #import "GroupADetailViewController.h"

@implementation GroupADetailViewController


@synthesize groupLabel = _groupLabel;
@synthesize groupADetail = _groupADetail;
@synthesize teamsInGroupA;

#pragma mark Memory management
- (void)dealloc {
    [_groupADetail release];
  [_groupLabel release];
  [super dealloc];
}

#pragma mark View lifecycle
- (void)viewDidLoad {
  [super viewDidLoad];

  // Set the number label to show the number data
 teamsInGroupA  = [[NSArray alloc]initWithObjects:@"France",@"Mexico",@"Uruguay",@"South Africa",nil];
    NSLog(@"loaded");
      // Set the title to also show the number data
    [[self navigationItem]setTitle:@"Group A"];



    //[[self navigationItem]cell.textLabel.text:@"test"];

    //[[self navigationItem] setTitle[NSString String
}

- (void)viewDidUnload {
  [self setgroupLabel:nil];
}

#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    // Return the number of sections in the table view
    return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in a specific section
    // Since we only have one section, just return the number of rows in the table
    return 4;
NSLog:("count is %d",[teamsInGroupA count]);
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    static NSString *cellIdentifier2 = @"Cell2";

    // Reuse an existing cell if one is available for reuse
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];

    // If no cell was available, create a new one
    if (cell == nil) {
        NSLog(@"no cell, creating");
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    NSLog(@"cell already there");

    // Configure the cell to show the data for this row
     //[[cell textLabel]setText:[NSString string

    //[[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]];
    //NSUInteger row = [indexPath row];


    //[cell setText:[[teamsInGroupA objectAtIndex:indexPath:row]retain]];
    //cell.textLabel.text:@"Test"   
    [[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]];
    return cell;
}


@end

#import "GroupADetailViewController.h"

@implementation GroupADetailViewController


@synthesize groupLabel = _groupLabel;
@synthesize groupADetail = _groupADetail;
@synthesize teamsInGroupA;

#pragma mark Memory management
- (void)dealloc {
    [_groupADetail release];
  [_groupLabel release];
  [super dealloc];
}

#pragma mark View lifecycle
- (void)viewDidLoad {
  [super viewDidLoad];

  // Set the number label to show the number data
 teamsInGroupA  = [[NSArray alloc]initWithObjects:@"France",@"Mexico",@"Uruguay",@"South Africa",nil];
    NSLog(@"loaded");
      // Set the title to also show the number data
    [[self navigationItem]setTitle:@"Group A"];



    //[[self navigationItem]cell.textLabel.text:@"test"];

    //[[self navigationItem] setTitle[NSString String
}

- (void)viewDidUnload {
  [self setgroupLabel:nil];
}

#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    // Return the number of sections in the table view
    return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in a specific section
    // Since we only have one section, just return the number of rows in the table
    return 4;
NSLog:("count is %d",[teamsInGroupA count]);
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    static NSString *cellIdentifier2 = @"Cell2";

    // Reuse an existing cell if one is available for reuse
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];

    // If no cell was available, create a new one
    if (cell == nil) {
        NSLog(@"no cell, creating");
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    NSLog(@"cell already there");

    // Configure the cell to show the data for this row
     //[[cell textLabel]setText:[NSString string

    //[[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]];
    //NSUInteger row = [indexPath row];


    //[cell setText:[[teamsInGroupA objectAtIndex:indexPath:row]retain]];
    //cell.textLabel.text:@"Test"   
    [[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]];
    return cell;
}


@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitableview