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

℡╲_俬逩灬. 提交于 2019-12-03 04:32:00

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
       }
Abhishek Singh

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!