0

我正在尝试从我的主包中加载一个 plist,但它运行得不太好。我不断得到一个无效的 CFStringRef ,这导致我想要的所有显示都为零。

让这更奇怪。它在模拟器中完美运行。我附上了这张图片来帮助解释。

http://img847.imageshack.us/img847/1185/screenshot20110325at120m.png

这对我来说没有任何意义。它可以在模拟器中运行,为什么它不能在设备上运行?

- (void)viewDidLoad {
    [super viewDidLoad];
    imageV = [[UIImage alloc]init];
    imageV = [UIImage imageNamed:[NSString stringWithFormat:@"%@", imageTitle]];


    button = [UIButton buttonWithType:UIButtonTypeCustom];

    CGRect frame = CGRectMake(0, 0, 320, 65);
    button.frame = frame;   // match the button's size with the image size

    [button setBackgroundImage:imageV forState:UIControlStateNormal];




    [button addTarget:self action:@selector(adClicked:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    [self.view addSubview:button];

    NSLog(@"%i %@", [self.view.subviews count], webLink);

}

在模拟器和设备中,控制台报告在每个创建的视图中都有一个子视图。在模拟器中,按钮被添加并出现,其图像已更改。但是,在设备上,该按钮不会出现,其图像已更改。虽然它说按钮在那里,但它根本没有出现,我也无法与它交互,以防图像没有设置。

//addScroller.m 我已经尝试清理目标并将图像直接添加到应用程序文件夹中......我什么也没得到。我的下一个赌注是它与我从 plist 文件或其他东西加载它的事实有关。我确实重命名了 ads 文件夹并将其设为小写,并且几乎是从头开始的。plist会导致问题吗?我加载它的方式是改变文件大小写还是修改字符串?

- (void)viewDidLoad {
    [super viewDidLoad];
    adIndex = 0;
    adTimer = [[NSTimer alloc]init];
    ad = [[Ad alloc]init];
    adsList = [[NSMutableDictionary alloc]init];
    item = [[NSDictionary alloc]init];
    filePath = [[NSString alloc]init];

        filePath = [[NSBundle mainBundle] pathForResource:@"Ads" ofType:@"plist"];
    NSLog(@"%@", filePath);
        adsList = [[[NSMutableDictionary alloc] initWithContentsOfFile:filePath]retain];

        for (int i = 0; i < [adsList count]; i++) {
            item = [[NSDictionary alloc]init];
            item = [adsList valueForKey:[NSString stringWithFormat:@"%i", i ]];
            ad = [[Ad alloc] initWith:[item objectForKey:@"adImage"] Link:[item objectForKey:@"website"]];

            //[ads addObject:a];

            ad.view.frame = CGRectMake(320 * i, 0, 320, 65);

            [adsView addSubview:ad.view];

            [item release];
        }
        [adsView setContentSize:CGSizeMake(320 * [adsList count], 65)];
        adsView.pagingEnabled = YES;

    adIndex = HBRandomInt([adsList count]);
    [self scrollAds];
   [NSTimer scheduledTimerWithTimeInterval:8.0 
                                 target:self 
                               selector:@selector(scrollAds) 
                               userInfo:nil
                                repeats:YES];
    //[adTimer release];
    //[ad release];
    //[item release];
    //[adsList release];

}

编辑:我在应用程序的其他地方加载了图片,效果很好

4

2 回答 2

0

不要使用[[NSString alloc] init];

尝试NSString *filePath = nil;

于 2011-03-26T17:26:52.957 回答
0

模拟器 (Mac) 不区分大小写。该设备是。这通常是导致在模拟器中似乎可以正常工作的设备上加载资源的问题。

于 2014-06-25T15:50:26.493 回答