从plist检索数据为空

时间:2013-05-28 11:24:03

标签: ios plist tableview

我无法在CustomCell中显示项目。如果我的名字如namesurname,一切正常。但是当我删除surname field并将它们放在一个字段中时,它们就是null。我想这是因为space character。离场也是如此。我不知道如何解决这个问题。我是IOS开发的新手。

AppDelegate.m:

-(void)chackDB{

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSString *docPath = [[self documentsDirectory]stringByAppendingPathComponent:@"drList.plist"];

    if([fileManager fileExistsAtPath:docPath]) return;

    NSString *sourcePath = [[NSBundle mainBundle]
                            pathForResource:@"drList" ofType:@"plist"];
    NSError *err=nil;
    [fileManager copyItemAtPath:sourcePath toPath:docPath error:&err];

    if(err){

        NSLog(@"hata: %@",[err description]);
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self chackDB];

这是我的plist:

    <array>
        <dict>
            <key>depart</key>
            <string>Plastic Surgery</string>
            <key>name</key>
            <string>John Smith</string>
        </dict>
    </array>

我的代码:

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

    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:cellID];

    if (cell == nil)
    {
        cell = (CustomCell*)[[[NSBundle mainBundle]
                              loadNibNamed:@"CustomCell" owner:nil options:nil]
                             lastObject];
    }

    // customization
    NSDictionary *d = [self.dataList objectAtIndex:indexPath.row];

    cell.nameLabel.text = [NSString stringWithFormat:@"%@",
                           [d objectForKey:@"name"]];

    cell.departLabel.text = [NSString stringWithFormat:@"%@",
                           [d objectForKey:@"depart"]];


    cell.indexPath = indexPath;


    return cell;
}

当我选择行时,这是DetailViewController:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.name.text = [NSString stringWithFormat:@"Name: %@",[self.userInfo objectForKey:@"name"]];
    self.depart.text = [NSString stringWithFormat:@"Department: %@",[self.userInfo objectForKey:@"depart"]];

}

0 个答案:

没有答案