Мога да получа данни от plist, но изглежда, че моят cellForRowAtIndexPath не се извиква, тъй като никой от NSLog не отпечатва нищо от вътрешността на метода.
ето моят код: -
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"drinks" ofType:@"plist"];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
self.drinks = [tempDict objectForKey:@"Root"];
NSLog(@"%@", self.drinks);
NSLog(@"Number = %d", self.drinks.count);
[super viewDidLoad];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSLog(@"I am inside cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSArray *allValues = [self.drinks valueForKey:@"name"];
NSLog(@"%d", allValues.count);
cell.textLabel.text = [allValues objectAtIndex:indexPath.row];
return cell;
}
Ето изхода ми от конзолата: -
2011-10-01 20:27:01.940 DrinkMixer[1832:b303] (
{
directions = "Shake adahsdk adlkasd";
ingredients = "kslkds lkjsjlkd kjsljlakj aajdlkj";
name = "Fire Cracker";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Lemon Drop";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = Mojito;
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "After Drink Mint";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Apple Martini";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Shockwave";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Beer";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Last Desire";
},
{
directions = "abds fedfsdkkjkljlkj;j ok";
ingredients = "hasdhalsdlash asdhasldh kjdfkjshdj";
name = "Vodka";
}
)
2011-10-01 20:27:01.942 DrinkMixer[1832:b303] Number = 9
Нито един NSLog на cellForRowAtIndexPath не се извиква.
Може ли някой да каже какво не е наред с този код.
Благодаря.