[英]Crash on tap of didSelectRow for going to another viewcontroller
[英]On images tap, open another ViewController
我的視圖控制器中有3個視圖,這些視圖由UISegmentControl
控制,因此一旦單擊每個視圖,它將在每個視圖之間切換。 現在請記住,它們都是堆疊在一起的,最初是2個隱藏的,幾乎可以切換為顯示/隱藏其他兩個。
我正在嘗試設置它,以便一旦在3個視圖中的任何一個內點擊一個區域,它就會打開另一個視圖控制器。 如何在我的視圖控制器中為所有3個視圖執行此操作? 我的視圖由一堆模仿一個表列表的UIImages
組成(這是一個原型應用程序)。 每個視圖都不會占據整個屏幕,因為我確實在頂部有一個標題欄,在底部有一個搜索欄,以及一個tabcontroller。
如果您有對圖像的引用(UIImageView組件),則可能應該向所有圖像添加一個UITapGestureRecognizer來檢測點擊。
例如在viewDidLoad中:
UITapGestureRecognizer *img1TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController1:);
[imageView1 addGestureRecognizer:img1TapGestureRecognizer];
UITapGestureRecognizer *img2TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController2:);
[imageView2 addGestureRecognizer:img2TapGestureRecognizer];
UITapGestureRecognizer *img3TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController3:);
[imageView3 addGestureRecognizer:img3TapGestureRecognizer];
然后通過以下方法顯示視圖控制器:
- (void)displayViewController1:(UITapGestureRecognizer *)recog {}
- (void)displayViewController2:(UITapGestureRecognizer *)recog {}
- (void)displayViewController3:(UITapGestureRecognizer *)recog {}
嘗試這個
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view] == yourDesiredImage) {
// Do something here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.