Same code, not the same place, different results
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-03-19T12:34:45Z
Indexed on
2010/03/19
12:51 UTC
Read the original article
Hit count: 288
Hi!
I'm trying to something pretty simple but I don't understand why the second bit of code is giving me a bad access error...
First:
- (UITableViewCell *)tableView:tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Tom: Converting the row int to a string and adding 1 to it so that the rows fit with the array indexes.)
NSString *key = [NSString stringWithFormat:@"%d", indexPath.row+1];
NSArray *array = [self.tableDataSource objectForKey:key];
NSLog(@"%@", key);
NSLog(@"%@", [array description]);
cell.textLabel.text = [array objectAtIndex:1];
return cell;
}
That code gives me exactly what I want:
2010-03-18 15:18:12.884 PremierSoins[28005:40b] 1
2010-03-18 15:18:12.885 PremierSoins[28005:40b] (
7,
Blessures
)
2010-03-18 15:18:12.892 PremierSoins[28005:40b] 2
2010-03-18 15:18:12.893 PremierSoins[28005:40b] (
18,
"Test 2"
)
But then, the second:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = [NSString stringWithFormat:@"%d", indexPath.row+1];
NSArray *array = [self.tableDataSource objectForKey:key];
NSLog(@"%@", key);
NSLog(@"%@", [array description]);
}
Is only able to get me the key, but the description of the array makes it crash...
tableDataSource is a NSMutableDictionary containing multiple arrays...
Like this:
{
1 = (
7,
Blessures
);
2 = (
18,
"Test 2"
);
}
Do you have any clue? I've been looking at this since yesterday...
Thanks!
- Tom
© Stack Overflow or respective owner