2012-03-25 21 views
0

뷰 컨트롤러에 뷰 모음이 있습니다. 예를 들어 특정 데이터를로드하고 싶은 뷰 중 하나를 터치하면됩니다. 동일한보기 컨트롤러에있는 웹보기로 웹 페이지UIView를 터치하여 WebView에 내용을로드하는 방법

어떻게 수행하겠습니까? UITapGestureRecognizer

UIView *categoryTitle = [[UIView alloc] initWithFrame:CGRectMake(0, 166 * counter 
                    , 500, 20)]; 

    UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 20)]; 

    [categoryLabel setBackgroundColor:[UIColor clearColor]]; 
    NSMutableArray *allCurrentNews = [[News alloc] allNewsFromCategory:cat.CategoryId]; 

    categoryLabel.text = cat.Name; 
    categoryLabel.textColor = [UIColor whiteColor]; 

    [categoryTitle addSubview:categoryLabel]; 

    UIColor *myblack = [[UIColor alloc] initWithRed:0.14 green:0.14 blue:0.14 alpha:1]; 
    UIColor *ligheterBlac = [[UIColor alloc] initWithRed:0.227 green:0.22 blue:0.22 alpha:1]; 
    [categoryTitle setBackgroundColor:myblack]; 

    UIScrollView *tempScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 166 * counter, 500, 166)]; 

    UIColor *tempcolor = ligheterBlac; 
    tempScroll.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor; 
    tempScroll.layer.borderWidth = 0.5f; 
    int countnews = 0; 

    for (News *news in allCurrentNews) 
    { 
     UIView *newsContainer = [[UIView alloc] initWithFrame:CGRectMake(160 * countnews, 30, 156, 126)]; 
     newsContainer.tag = countnews + 1; 
     [newsContainer addGestureRecognizer:recognizer]; 

     //newsContainer.NewsId = news.NewsId; 
     LazyImageView *image = [[LazyImageView alloc] initWithURl:[NSURL URLWithString:news.Thumbnail]]; 
     image.frame = CGRectMake(0, 0 , 156, 96); 
     UILabel *newsTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 96, 156, 30)]; 
     newsTitle.backgroundColor = myblack; 
     newsTitle.numberOfLines = 2; 
     newsTitle.font = [UIFont systemFontOfSize:11]; 
     newsTitle.text = news.Title; 
     newsTitle.textColor = [UIColor whiteColor]; 
     newsTitle.textAlignment = UITextAlignmentCenter; 

     newsContainer.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor; 
     newsContainer.layer.borderWidth = 0.5f; 

     [newsContainer addSubview:image]; 
     [newsContainer addSubview:newsTitle]; 

     countnews ++; 
     [tempScroll setContentSize:CGSizeMake(allCurrentNews.count * 156, 96)]; 
     [tempScroll addSubview:newsContainer]; 
     //[image release]; 
    } 

    [tempScroll setBackgroundColor: tempcolor]; 

    [categories addSubview:tempScroll]; 
    [categories addSubview:categoryTitle]; 
    [tempcolor release]; 
    [tempScroll release]; 
    counter ++; 
} 

self.detailsView.layer.masksToBounds = NO; 
self.detailsView.layer.shadowOffset = CGSizeMake(-10, 5); 
self.detailsView.layer.shadowRadius = 5; 
self.detailsView.layer.shadowOpacity = 0.3; 

[self.view addSubview:categories]; 
[self.view addSubview:_detailsView]; 
[self.view addSubview:MainSubTitle]; 
[self.view addSubview:MainTitle]; 

답변

0

사용 :

다음은 작동하지 않습니다 내 코드가

사전

에 감사드립니다.

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:selector(processTap:)]; 
    UIView *targetView = //assign the view you need 
    targetView.tag = 5; 
    [targetView addGestureRecognizer:recognizer]; 
} 

- (void)processTap:(UITapGestureRecognizer *)recognizer { 
    UIView *view = recognizer.view; 
    if (view.tag == 5) { 
    } 
} 
+0

나는 선언되지 않은 식별자 "processTap" 및 "기능 선택의 암시 적 선언은 C99에서 유효하다" – Alexidze

+0

음은 아주 기본적인 물건의 사용을 얻는다. 이 줄을 추가하십시오 - (void) processTap : (UITapGestureRecognizer *) recognizer; .h 파일 또는 .m 파일의 개인 확장. – Eugene

+0

나는 모든 것을했지만 여전히 호출되지 않는다. – Alexidze

관련 문제