Buttons and Images are not being added to the view on Device (works in simulator)
I'm trying to load a plist from my main bundle and it isn't working too well. I keep geting a invalid CFStringRef which results in a nil for all the displays that I wanted.
To make this even more odd. It works perfectly in the simulator. I have attached this image to help explain.
http://img847.imageshack.us/img847/1185/screenshot20110325at120m.png
This doesn't make any sense to me. It works in simulator, by why doesn't it work on the device?
- (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);
}
in both the simulator and device the console reports that there is one subview in each view created. In the simulator the button is added and appears with its image changed. However On the Device the button does not appear with its image changed. though it says the button is there it simply doesn't appear and I can't interact with it either incase the image just wasn't setting开发者_JAVA百科.
//addScroller.m I've tried cleaning the target and adding the images directly to the app folder... I got nothing. my next bet is that it has something to do with the fact that i'm loading it from a plist file or something. I did rename the ads folder and made it lower case and started pretty much from scratch. would the plist be causing the issue? is the way in which I've loaded it changing the file casing or modifying the strings?
- (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];
}
EDIT: I loaded the picture elsewhere in the app and it worked fine
The simulator (Mac) isn't case sensitive. The device is. This is often what causes problems loading resources on a device that seem to work just fine in the simulator.
Don't use [[NSString alloc] init];
Try NSString *filePath = nil;
精彩评论