1)我通過使用自定義 協議的兩個視圖控制器之間傳遞值。但該值始終顯示NULL。使用自定義協議在兩個視圖控制器之間傳遞數據值
我需要從第二視圖控制器值傳遞給第一視圖控制器
2)在Secondview或者Controller.h
@protocol PopoverTableViewControllerDelegate <NSObject>
@property (nonatomic, strong) id<PopoverTableViewControllerDelegate>myDelegate;
3)secondview Controller.m或者
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary*dict=[sercharray objectAtIndex:index];
str=[dict objectForKey:@"id"];
NSLog(@"test value %@",str);
[self.myDelegate didSelectRow:str];
NSLog(@"delegate value %@",self.myDelegate);
//THIS VALUE ALWAYS SHOWING NULL AND ALSO I SHOULD PASS THIS VALUE TO FIRST VIEW
CONTROLLER.I SHOULD USE DISMISS VIEW CONTROLLER.
[self dismissViewControllerAnimated:YES completion:nil];
}
4 )第一視圖controller.h
@interface Firstviewcontroller :
UIViewController<PopoverTableViewControllerDelegate>
5)首先查看Controller.m或者
secondviewcontroller *next=[[seconviewcontroller alloc]init];
next.myDelegate=self;
(void)didSelectRow:(NSString *)cellDataString {
passstring = cellDataString;
NSLog(@"pass string %@",pass string);
//first view controller str variable value i need to pass this string[passstring].
}
您是否在第二視圖controller.m中獲得了str的值? –
是的,我的第二視圖controller.m –
str得到的價值是您的secondViewController委託方法在解散後在您的FirstViewController類中調用.. –