I have a method I am calling from my mainview that is setting the image name of the image I want to display in a scrollview.
- (void)loadImage:(NSString *)myImageName
{
if (myImageName == @"one") {
imageName = myImageName;
}
if (myImageName == @"two") {
imageName = myImageName;
}
if (myImageName == @"three") {
imageName = myImageName;
}
//Reloads view here???
}
I am loading the images in my viewdidload method like so
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Create scrollview
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.delegate = self;
scrollView.bounces = NO;
//Create scrollviewimage
if (imageName == @"one") {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ha.png"]];
}
if (imageName == @"two") {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"haha.png"]];
}
if (imageName == @"three") {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hahaha.png"]];
}
containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 550)];
//Add subview
[containerView addSubview:image];
//initViews
scrollView.contentSize = containerView.frame.size;
[scrollView addSubview:containerView];
//scrolling
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
//highrachy
[self.view addSubview:scrollView];
}
What happens when I set the imagename from the parentview from a tableviewcell selection I pass down the nsstring into loadImage.. then load image sets the name in viewdidload.. however what is happening is that only the first selection dose anything.. so you will always see the first image you are selecting.. so if you pick image two every other image you select will show image two..
any help would be great.
here is what the parentview cell selection looks like
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];
if (!self.detailViewController) {
self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];
if (indexPath.section == 0) {
_detailViewController.imageName = @"one";
// NSLog(@"%@", indexPath);
}
if (indexPath.section == 1) {
_detailViewController.imageName = @"two";
// NSLog(@"%@", indexPath);
}
if (indexPath.section == 2) {
_detailViewController.imageName = @"three";
// NSLog(@"%@", indexPath);
}
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
Don’t use myImageName == @”three”. There’s a special method for comparing strings.
try this:
If there is a file extension, do this:
By the way, you are still posting the old code you had in your other question. You are retaining your detailView in your original class instead of releasing and creating a new instance. Take out the if (!detailView) statements.
Update: the only other option is to take the assignments out of the large if( ) block.
The only other way is this: