How to pass data back from detail view controller to uitableview?

前端 未结 2 762
长发绾君心
长发绾君心 2021-02-06 10:45

In my app i making use of uitable to select category from my list. my task is,when ever user click or select a cell he should be able to view the selected cell detail in next vi

相关标签:
2条回答
  • 2021-02-06 11:13

    You need to make use of custom delegates. Create a protocol in your detailview and implement it in your rootview.Pass the selected string as parameter to delegate method and from the delegate method, display it in your textfield.

    //something like this
    @interface detailViewController
    
    // protocol declaration 
    @protocol myDelegate
    @optional
       -(void)selectedValueIs:(NSString *)value;
    
    // set it as the property
    @property (nonatomic, assign) id<myDelegate> selectedValueDelegate;
    
    // in your implementation class synthesize it and call the delegate method
    @implementation detailViewController
    @synthesize selectedValueDelegate
    // in your didselectRowAtIndex method call this delegate method
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
     {
    
          [self  selectedValueDelegate])selectedValueIs:valueString] ;
          [self.navigationController popViewControllerAnimated:YES];
    
      }
    
    
    
    
    @end
    
    // In your rootViewController conform to this protocol and then set the delegate
    
             detailViewCtrlObj.selectedValueDelegate=self;
    //Implement  the delegate Method 
         -(void)selectedValueIs:(NSString *)value{
           {
                // do whatever you want with the value string
           }
    
    0 讨论(0)
  • 2021-02-06 11:17

    Hi you will have to do it using protocols and delegate Please see my linkon protocol and delegate

    you can also do it by creating a variable in appdelegate , setting its property and accessing it in any other view .

    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    delegate.yourVariable;
    
    0 讨论(0)
提交回复
热议问题