我无法在CustomCell中显示项目。如果我的名字如name
和surname
,一切正常。但是当我删除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"]];
}