UITableView值与其键形式plist不匹配

时间:2014-03-08 11:59:24

标签: objective-c uitableview plist

我正在为iOS制作一个plist查看器和编辑器,但我遇到的问题是,这些值与其键不匹配。就像我有这个plist

{
        BuildMachineOSBuild = 12C54;
        CAProcessCanAccessGPU = 1;
        CFBundleAllowMixedLocalizations = 1;
        CFBundleDevelopmentRegion = English;
        CFBundleDisplayName = iAd;
        CFBundleExecutable = AdSheet;
        CFBundleIconFiles =         (
            "iAd.png",
            "iAd@2x.png"
        );
        CFBundleIcons =         {
            CFBundlePrimaryIcon =             {
                CFBundleIconFiles =                 (
                    "iAd.png",
                    "iAd@2x.png"
                );
                UIPrerenderedIcon = 0;
            };
        };
        CFBundleIdentifier = "com.apple.AdSheetPhone";
        CFBundleInfoDictionaryVersion = "6.0";
        CFBundleName = AdSheet;
        CFBundlePackageType = APPL;
        CFBundleResourceSpecification = "ResourceRules.plist";
        CFBundleShortVersionString = "1.0";
        CFBundleSignature = "????";
        CFBundleSupportedPlatforms =         (
            iPhoneOS
        );
        CFBundleVersion = "1.0";
        CLSystemService = 1;
        CLVisibleImmediately = 1;
        CanInheritApplicationStateFromOtherProcesses = 1;
        DTCompiler = "com.apple.compilers.llvm.clang.1_0";
        DTPlatformBuild = "";
        DTPlatformName = iphoneos;
        DTPlatformVersion = "7.0";
        DTSDKBuild = 11A450;
        DTSDKName = "iphoneos7.0.internal";
        DTXcode = 0500;
        DTXcodeBuild = 5A1344i;
        MinimumOSVersion = "7.0";
        NSPrincipalClass = ADSApplication;
        SBAppTags =         (
            hidden
        );
        SBMachServices =         (
            "com.apple.AdSheetPhone.server",
            "com.apple.AdSheetPhone.management",
            "com.apple.uikit.viewservice.com.apple.AdSheetPhone"
        );
        UIBackgroundModes =         (
            continuous
        );
        UIDeviceFamily =         (
            1,
            2
        );
        UIShouldIgnoreRemoteControlEvents = 1;
        UIStatusBarHidden = 1;
        UISupportedInterfaceOrientations =         (
            UIInterfaceOrientationPortrait,
            UIInterfaceOrientationPortraitUpsideDown,
            UIInterfaceOrientationLandscapeLeft,
            UIInterfaceOrientationLandscapeRight
        );
        UIViewServiceUsesNSXPCConnection = 1;
    }
)

我尝试显示值及其键(或词典的词典,阵列的数组和Bool的Bool)

然后例如CanInheritApplicationStateFromOtherProcesses应显示1(它是一个BOOL),但不显示任何值。 CanInheritApplicationStateFromOtherProcesses位于我的UITableView的索引0上,但它位于plist的索引19上。有谁知道如何解决此错误。我在cell.textLabel.text中显示密钥,在cell.detailTextLabel.text中显示该值。这是我的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;代码:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"plist Cell" forIndexPath:indexPath];
id obj;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.detailTextLabel.minimumScaleFactor = 0.5;
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
cell.editingAccessoryType = UITableViewCellEditingStyleNone;
if (self.plistDict) {
    NSString* key = [[self.plistDict allKeys] objectAtIndex:indexPath.row];

    cell.textLabel.text = key;
    obj = [self.plistDict objectForKey:key];
} else {
    cell.textLabel.text = [NSString stringWithFormat:@"%li", (long)indexPath.row];
    obj = [self.plistArray objectAtIndex:indexPath.row];
}
if(([obj isKindOfClass:[NSArray class]] || [obj isKindOfClass:[NSMutableArray class]]) && cell.tag == 0){
    cell.detailTextLabel.text = NSLocalizedString(@"Array", nil);
    cell.tag = 1;
    return cell;
} if(([obj isKindOfClass:[NSDictionary class]] || [obj isKindOfClass:[NSMutableDictionary class]]) && cell.tag == 0){
    cell.detailTextLabel.text = NSLocalizedString(@"Dictionary", nil);
    cell.tag = 2;
    return cell;
} if ([obj isKindOfClass:[NSString class]] && cell.tag == 0) {
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", (NSString *)obj];
    cell.tag = 3;
    return cell;
} if ([obj isKindOfClass:[NSNumber class]]) {
    if ([obj isKindOfClass:[@(YES) class]] && cell.tag == 0) {
        [boolSwitch setOn:(BOOL)obj animated:YES];
        [cell.contentView addSubview:boolSwitch];
        cell.detailTextLabel.textColor = [UIColor clearColor];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.tag = 7;
        return cell;
    } else if (![obj isKindOfClass:[@(YES) class]] && cell.tag == 0) {
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", (NSNumber *)obj];
        cell.tag = 4;
        return cell;
    } else {
        return cell;
    }

} if ([obj isKindOfClass:[NSData class]] && cell.tag == 0) {
    cell.detailTextLabel.text = NSLocalizedString(@"Data", nil);
    cell.tag = 5;
    return cell;
} if ([obj isKindOfClass:[NSDate class]] && cell.tag == 0) {
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", (NSDate *)obj];
    cell.tag = 6;
    return cell;
} else {
    return cell;
}

奇怪的是,值匹配的键数最多,但不是全部。

1 个答案:

答案 0 :(得分:0)

单元格将与标签一起重复使用。所以你可能应该在重用单元格之前重置标签:

//CustomeCell.m
- (void)prepareForReuse{
    [super prepareForReuse];
    self.tag = 0;

}

或者在tableView委托类中:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.tag = 0;

}