我有一個用於顯示彈出窗口(在iPhone上)的自定義UIView。在popover中有一些UIButtons,我需要從ViewController的類(不是UIView的類,但顯示UIView的View)調用方法。iOS Subclassed UIView - 如何從ViewController的UIButton調用方法?
如何正確設置呢?位於自定義UIView類
的UIView按鈕代碼:
UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeCustom];
[logoutButton setTitle:@"Logout" forState:UIControlStateNormal];
[logoutButton setFrame:CGRectMake(0, 0, content.frame.size.width, 44)];
[logoutButton addTarget:self.superview.superview action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
[logoutButton setBackgroundImage:redImage forState:UIControlStateNormal];
[logoutButton setBackgroundImage:redImageHighlight forState:UIControlStateHighlighted];
[logoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[content addSubview:logoutButton];
視圖不應該負責非觀看邏輯諸如呈現酥料餅。您應該處理按鈕的觸摸事件和視圖控制器,並從那裏呈現彈出窗口。 – titaniumdecoy