10

के माध्यम से प्रस्तुत प्रस्तुत मोडल व्यू कंट्रोलर को खारिज करने के बाद UIViewController में ताज़ा डेटा मेरे पास काम करने वाला प्रतिनिधि है क्योंकि डेटा को मोडल से प्रस्तुत करने वाले व्यू कंट्रोलर में पास किया जा रहा है। लेकिन प्रस्तुत करने वाला दृश्य नियंत्रक मोडल से प्राप्त डेटा नहीं दिखा रहा है। मैंने अन्य पदों पर ध्यान दिया और वे प्रतिनिधि/प्रोटोकॉल विधि का उपयोग करने के लिए कहते हैं, लेकिन यह समझाएं कि प्रस्तुत करने वाले वीसी रीफ्रेश कैसे/क्यों। मुझे लगता है कि मेरा प्रतिनिधि गलत तरीके से सेटअप है। अन्यथा, डेटा रीफ्रेश करने का तरीका क्या है? मैंने जांच की है और viewWillAppear और viewDidAppear को कॉल नहीं किया जाता है।प्रतिनिधि

SCCustomerDetailVC.h (पेश कुलपति)

#import "SCCustomersVC.h" 

@interface SCCustomerDetailVC : UIViewController <SCCustomersVCDelegate> 

@property (atomic, strong) SCCustomer *customer; 
@property (strong, nonatomic) IBOutlet UIButton *changeCustomerButton; 

- (IBAction)changeCustomerButtonPress:(UIButton *)sender; 

@end 

SCCustomerDetailVC.m (पेश कुलपति)

- (IBAction)changeCustomerButtonPress:(UIButton *)sender 
{  
    UINavigationController *customersNC = [self.storyboard instantiateViewControllerWithIdentifier:@"customersNC"]; 
    SCCustomersVC *customersVC = (SCCustomersVC *)customersNC.topViewController; 
    customersVC.delegate = self; 
    [self presentViewController:customersNC animated:YES completion:nil]; 
} 

//Protocol methods 
- (void)passCustomer:(SCCustomer *)customer 
{ 
    self.customer = customer; 

    //At this point, self.customer has the correct reference 

    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

SCCustomersVC.h (मॉडल कुलपति)

#import "SCCustomersVCDelegate.h" 

@class SCCustomerDetailVC; 

@interface SCCustomersVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate> 

@property (weak, nonatomic) id <SCCustomersVCDelegate> delegate; 

@end 

SCCustomersVC.m (मॉडल वीसी)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    SCCustomer *customer = [self customerAtIndexPath:indexPath]; 
    [self.delegate passCustomer:customer]; 
} 

SCCustomersVCDelegate.h

@class SCCustomer; 

@protocol SCCustomersVCDelegate <NSObject> 
@optional 

- (void)passCustomer:(SCCustomer *)customer; 

@end 
+0

आप प्राप्त करने के बाद क्या किया आपके प्रतिनिधि में सही संदर्भ। – Zen

+0

@ जेन यूप, मैं इसके लिए आप सभी को परेशान करने के लिए खेद है। किसी कारण से, मैंने सोचा कि यह मेरी थका हुआ राज्य में अपनी आखिरी रात को "जादूगर" अपडेट करेगा। मुझे इसे अपडेट करने के लिए कोड जोड़ना होगा। – guptron

उत्तर

6

मुझे लगता है कि आप लगभग वहाँ हो करने के बाद अपना यूआई को फिर से लोड करना चाहिए। संपादित करें - बस here सीखा है कि IW> 5 में देखें WillAppear व्यवहार अलग है। आप अभी भी देखना चाहते हैं कि दृश्य आपके मॉडल स्थिति के साथ आपके दृश्य को अपडेट करने के लिए दिखाई देगा, क्योंकि इसे प्रारंभिक प्रस्तुति पर ऐसा करने की आवश्यकता है।

और इसे अपने मोडल वीसी या प्रतिनिधि विधि के भीतर से कॉल करना ठीक है। तो या तो प्रस्तुत कुलपति या प्रतिनिधि से फिर viewWillAppear करने के लिए कोड दृश्य नियंत्रक के मॉडल राज्य के साथ दृश्य को अद्यतन करता है कि ...

// SCCustomerDetailVC.m 
- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    // making up an IBOutlet called someLabel 
    // making up a model method (description) that returns a string representing your model 
    self.someLabel.text = [self.customer description]; 
} 

जोड़ने के लिए, फोन viewViewWillAppear:

- (void)passCustomer:(SCCustomer *)customer 
{ 
    self.customer = customer; 
    [self viewWillAppear:YES]; 
    [self dismissViewControllerAnimated:YES completion:^{}]; 
} 
+1

धन्यवाद दान, मैंने परिवर्तन किए हैं, और दृश्य में एक ब्रेक पॉइंट सेट किया है, लेकिन यह इसे मार नहीं रहा है। – guptron

+0

मुझे आईओएस में व्यवहार में बदलाव से अनजान था। मेरा संपादन देखें। – danh

+0

यूप, प्रतिनिधि विधि में कोड जोड़कर काम किया। धन्यवाद। – guptron

2

आप "ग्राहक"

- (void)passCustomer:(SCCustomer *)customer 
{ 
    self.customer = customer; 

    //At this point, self.customer has the correct reference 

    [self dismissViewControllerAnimated:YES completion:^{ 
      // reload your UI here or call a method which will reload your ui 
      // e.g. for tableView it will be [tableView reload]; 
     }]; 
} 
+0

बहुत बहुत धन्यवाद। यह मेरे लिए एक आकर्षण की तरह काम किया। – Manthan

+0

कोड को फिर से लोड करने के लिए कोड क्या होगा जो तालिका दृश्य का उपयोग नहीं करता है यानी बस पाठ लेबल? – user1904273

+0

E.g इस तरह कुछ label.text = customer.name –

संबंधित मुद्दे