2011-08-05 46 views
0

我是iPhone開發的綠色之手,我只是對一個方法UIActionsheet,即「showInView」感到困惑。那麼調用動作表的視圖和它自己的動作表之間的關係是什麼?
實際上,我想在動作表中自定義按鈕,所以我爲它創建了一個類並覆蓋了這些方法,並且我真的想要在superview中調用這些方法,任何人都可以獲得解決方案?如何獲取Actionsheet的容器​​類?

謝謝!
(順便說一句,我嘗試下面的代碼,但它不工作。)

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated 

{........ 
    else if (buttonIndex==sharers.count+1) 
    { 

    AddCommentViewController *parentController=(AddCommentViewController *)[self.superview nextResponder]; 
} 
+0

我看不出您顯示的代碼與自定義操作表按鈕或製作任何子類有關的任何內容。 – PeyloW

+0

它在AddCommentViewController中,我調用了自定義的工作表。此處的代碼位於Actionsheet類中,我想在AddCommentViewController中調用方法。 – user880449

回答

0

沒有公共API訪問的容器,或UIActionSheet所有者

您不應該使用superview屬性嘗試聯繫所有者,操作表的內部視圖佈局是私有的,並且可能會在操作系統更新之間發生變化。

如果您需要弄清所有者,請在UIActionSheet子類中添加適當的屬性來執行此操作。例如:

@protocol MYActionSheetChoiceDelegate; 

@interface MYActionSheet : UIActionSheet <UIActionSheetDelegate> {} 

@property(nonatomic, assign) id<MYActionSheetChoiceDelegate> choiceDelegate; 

@end 

請注意,我的名字屬性choiceDelegate因爲delegate財產已被使用。現在,假設你的子類也是你的它自己的UIActionSheetDelegate可以做到這一點:

-(void)actionSheet:(UIActionSheet*)sheet willDismissWithButtonIndex:(NSInteger)index; 
{ 
    if (index == SOME_INDEX) { 
     [self.choiceDelegate actionSheet:self didChooseSomething:index]; 
    } 
} 

變化並填補國內空白,以自己的需要。

+0

非常感謝。 – user880449