2017-11-11 161 views
0

我有一個叫做HomeViewController的ViewController。它的子視圖是(UIView)。 ActivityView的子視圖是ActivityCard(UIView)。在ActivityCard中,我有一個名爲Enter的按鈕。在它的點擊我需要將所有文本域的值從ActivityCard xib發送到HomeViewController並從那裏調用一個API。我以前從未與xib合作過,因此無法管理這種情況。任何幫助將不勝感激!發送按鈕上的值點擊從UIView到它的超級視圖的超級視圖(UIViewController)-iOS

編輯:

ActivityCard.h

@interface ActivityCard : UIView 


- (IBAction)actionEnterClick:(id)sender; 
@property (weak, nonatomic) IBOutlet UILabel *lblActivityCount; 
@property (weak, nonatomic) IBOutlet UIButton *enterButton; 

@end 

ActivityView.h

@interface ActivityView : UIView 

@property (strong) ActivityCard *card; 
@property (weak, nonatomic) IBOutlet iCarousel *carousel; 

@end 

ActivityView.m

- (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view 
{ 
if (view == nil) 
    { 
     _card = (ActivityCard*) [[[NSBundle mainBundle] loadNibNamed:@"ActivityCard" owner:nil options:nil] objectAtIndex:0]; 

     _card.frame = CGRectMake(0, 0, 280.0, 350.0); 
     _card.layer.cornerRadius = 10.0f; 
     view = _card; 
    } 
    return view; 
} 

HomeViewController.h

@interface HomeViewController : UIViewController 

@property (strong) ActivityView *viewActivity; 

@end 

HomeViewController.m

_viewActivity = (ActivityView*) [[[NSBundle mainBundle] loadNibNamed:@"ActivityView" owner:nil options:nil] objectAtIndex:0]; 
    _viewActivity.frame = CGRectMake(0.0f, 0.0f, _viewContainer.frame.size.width, _viewContainer.frame.size.height); 
    [_viewActivity updateActivityUI]; 

    for (UIView *child in _viewContainer.subviews) { 
     [child removeFromSuperview]; 
    } 
    [_viewContainer addSubview:_viewActivity]; 

    [_viewActivity.card.enterButton addTarget:self action:@selector(enterButtonDidTouch) forControlEvents:UIControlEventTouchUpInside]; 

    [_viewActivity.card.lblActivityCount setText:@"11"]; 

,當我們需要加載一個按鈕點擊ActivityView此代碼已被寫入。

回答

1

有很多方法可以做到這一點,我會告訴你一種方式,我認爲這是最簡單的方法。

  • ActivityCard.h
  • HomeViewController添加動作爲您Enter Button使用下面我的代碼創建Enter Button您所有的文本框的propertyproperty

    [self.activityView.cardView enterButton addTarget:self action:@selector(enterButtonDidTouch) forControlEvents:UIControlEventTouchUpInside]; 
    
  • HomeViewController.menterButtonDidTouch

    - (void)enterButtonDidTouch { 
        NSString *textOfTextField1 = self.activityView.activityCard.textField1.text; 
        // With the same way you can get others text of text fields and use them 
    } 
    
+0

的方法在某種程度上是沒有得到所謂的創建方法。任何我可能會缺少的東西? – Dia

+0

當我嘗試將標籤文本從HomeViewController設置爲ActivityCard時,它沒有正確設置值。我試過了:[_viewActivity.card.lblActivityCount setText:@「11」]; – Dia

+0

正如我所見,你做對了。你能告訴我你是如何實施它們的嗎? @Dia – trungduc

相關問題