2011-04-06 94 views
0

我正在构建一个允许用户滚动浏览图片的应用程序。由于我有很多图片(从网上下载),我所做的是我有父视图上的向上和向下按钮,此外我有滚动视图。根据选定的选项(向上或向下),我将ImageClass(创建一个扩展UIViewController的类)视图添加到滚动视图。在子视图控件上设置委托方法

现在,在选定的视图上,用户可以标记点或做任何事情。

问题是如何从父视图中调用Uiviewcontroller的方法。我知道如何设置委托方法,但我想要的是父控制器可以调用任何方法,比如重画整个视图的重绘方法。

代码:现在

-(IBAction) down:(id) sender{ 

    [scrollView2 removeFromSuperview]; 

} 

-(IBAction) down  :(id) sender { 

    [scrollView2 removeFromSuperview]; 
    if(scrollView2 == nil) 
     scrollView2 = [[UIScrollView alloc] init]; 
    [self.view addSubview:scrollView2]; 
    [self.view sendSubviewToBack:scrollView2]; 
    [scrollView2 setBackgroundColor:[UIColor blackColor]]; 
    [scrollView2 setCanCancelContentTouches:NO]; 
    scrollView2.clipsToBounds = YES;  
    // default is NO, we want to restrict drawing within our scrollview 

    scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite; 

    // CSImageView is a class which of the type UIViewController 
    imageVie = [[CSImageView alloc] init]; 
    [scrollView2 addSubview:imageVie.view]; 
    [scrollView2 setContentSize:CGSizeMake(1500,1500)]; 
    [scrollView2 setScrollEnabled:YES]; 
    [imageView release]; 
} 

,从父视图控制器我想打电话说:

imageVie.redraw();方法

代码CSImageView

@interface CSImageView : UIViewController { 

    NSNumber *imageId ; 

} 

@property (nonatomic, retain) NSNumber *venueId; 

-(void) redraw; 
@end 


@implementation CSImageView 


@synthesize imageId; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 


-(void) redraw { 
    NSLog(@"I am ehre in the test function"); 
} 
@end 

能否请你帮我在相同的。我无法调用重绘方法。任何输入将不胜感激。

回答

0

首先,CSImageView大概应该是UIView一个子类,而不是UIViewController。您应该保留对您的实例的引用(即作为实例变量或综合属性),以便您可以使用除- down:以外的方法访问它。

+0

嘿卡梅隆, 我也试过这样做。但我无法访问该方法。任何输入同样将不胜感激。请让我知道如何继续相同。 – Pintu 2011-04-06 20:16:03

0

哇。

我不能说我遵循你所编码的内容,但这是你如何去做的。

在此部分......添加了标签的视图

// CSImageView是一个类类型的UIViewController
imageVie = [[CSImageView的alloc] INIT];
imageVie.tag = 99 //任意数字。最好是一个常量
[scrollView2 addSubview:imageVie.view]; ...

然后父

视图控制器上。你可以...

- (IBAction为)跌:(ID)发送{

CSImageView *view = [scrollView2 viewWithTag:99]; 
[view redraw]; 

...}

类似的东西。