views:

284

answers:

1

hello, this is a part of my code. My application crashes when i try to load the view including the uitableview. i think there's a problem with the table i'm tryin to use but can't find it. help please

    gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];

declared in .h as NSArray *gameTimingTable; this is the code i'm using to assign the table to the uitableview

- (void)viewDidLoad {   

gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];



}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // There is only one section.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of time zone names.
    return [gameTimingTable count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";

    // Try to retrieve from the table view a now-unused cell with the given identifier.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    // If no cell is available, create a new one using the given identifier.
    if (cell == nil) {
     // Use the default cell style.
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    }

    // Set up the cell.
    NSString *cadence = [gameTimingTable objectAtIndex:indexPath.row];
    cell.textLabel.text = cadence;

    return cell;
}

/*
 To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected.
 */
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

thanks a lot

A: 

The problem here could be one (or both) of two things:

1...You are returning nil from the willSelectRowAtIndexPath method. If you don't a user to be able to tap the cells, simply don't override this method, i.e. don't touch it at all. Along with that, in the cellForRowAtIndexPath method you can do:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

to make sure that the cell doesn't even highlight when a user taps it.

2...The way you have initialised the array gameTimingTable means that it is autoreleased after you've created it so it cannot be accessed elsewhere in the code. Initialise it using either of the following methods instead:

gameTimingTable=[[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil] retain];

// OR ...

 gameTimingTable=[[NSArray alloc] initWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];

... but remember to release the array in the dealloc method:

- (void)dealloc {
[gameTimingTable release];
[super dealloc];

}

imnk