2012-03-25 36 views
0

Iビューコントローラにビューのコレクションがあります。それらのビューの1つに触れることによって、私は特定のデータをロードしたいと思います。同じビューコントローラにあるウェブビューにウェブページを表示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

私はまあそれはかなり基本的なものだ – Alexidze

+0

「関数セレクターの暗黙的な宣言がC99で無効である」宣言されていない識別子「processTap」 の使用を取得します。この行を追加する - (void)processTap:(UITapGestureRecognizer *)recognizer; .hファイルまたは.mファイルのプライベートエクステンションにコピーします。 – Eugene

+0

私はすべてをやったが、それでも呼び出されることはありません – Alexidze

関連する問題