我有一個方法,我從我的主視圖調用,即設置我想要顯示在滾動視圖中的圖像的圖像名稱。如何重新加載當前UIView
- (void)loadImage:(NSString *)myImageName
{
if (myImageName == @"one") {
imageName = myImageName;
}
if (myImageName == @"two") {
imageName = myImageName;
}
if (myImageName == @"three") {
imageName = myImageName;
}
//Reloads view here???
}
我加載在我viewDidLoad方法的相似圖片時,我設置爲從parentview的imagename從tableviewcell選擇我NSString的向下傳遞到的LoadImage所以
- (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];
}
會發生什麼事..然後載荷圖像設置viewdidload中的名稱..但是,發生的事情是,只有第一個選擇劑量任何東西..所以你總是會看到你選擇的第一個圖像..所以,如果你選擇圖像兩個你選擇的每個其他圖像將顯示圖像二..
an Ÿ幫助會很好。
這裏是parentview小區選擇是什麼樣子
- (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];
}
opps現在這樣做。 – 2012-01-31 22:19:29
它工作?爲了更加清晰,我更新了答案。 – Justin 2012-01-31 22:57:57