Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS-当有多个键时,如何显示plist中的数据?_Iphone_Ios_Plist - Fatal编程技术网

Iphone iOS-当有多个键时,如何显示plist中的数据?

Iphone iOS-当有多个键时,如何显示plist中的数据?,iphone,ios,plist,Iphone,Ios,Plist,我可以从plist获取数据,但似乎我的cellforrowatinedexpath没有被调用,因为NSLog没有从方法内部打印任何内容 这是我的密码:- - (void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@"drinks" ofType:@"plist"]; NSMutableDictionary *tempDict = [[NSMutableDictionary allo

我可以从plist获取数据,但似乎我的cellforrowatinedexpath没有被调用,因为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
未调用cellForRowAtIndexPath的NSLog

谁能告诉我这个代码有什么问题吗


谢谢。

可能是您没有在头文件中实现
UITableViewDelegate
,或者您的
UITableView
datasource
delegate
没有连接到nib文件中

我建议查看
数据源

更新:

如果没有调用
tableView:cellforrowatinexpath:
,并且
datasource
设置正确,那么可能是在加载
UITableView
之后,plist被加载到了
self.drinks
。证据可能是向上和向下滚动空的
UITableView
,查看屏幕外的单元格是否开始出现

我建议两件事:

  • 调用
    [super viewDidLoad]
    -(void)viewDidLoad的开头

  • 加载plist后,调用重新加载UITableView

  • 尝试:

    最后,我担心
    数据源的原因是因为我认为即使是空单元格也应该调用
    tableView:cellforrowatinexpath:


    希望这有帮助。

    一切都在正确的位置。这段代码以前可以工作,但我对plist做了一些更改,之后它就停止工作了,尽管我仍然能够从plist获取数据,正如您可以看到的控制台跟踪。我不知道我做错了什么。我终于解决了这个问题。多么愚蠢的错误啊。该死的!!我从numberOfRowsInSection返回了一个错误的值。谢谢你试着帮助我。我真的很感激,酷。很高兴你找到了答案。这段代码没有错,所以你的错误一定在别的地方。是否调用了任何tableView方法?例如,返回了多少行?我已经解决了这个问题。我犯了一个愚蠢的错误。我从方法numberOfRowsInSection返回了错误的值。谢谢你试着帮助我。我真的很感激。
    - (void)viewDidLoad {
    
        [super 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);    
    
        [yourTableView reload];
    
    }