开发者

Problem in passing data values between classes through delegation object c

I just want to transfer data from MyCoolViewController to firstViewController.

I have a problem with trasferring data from MyCoolViewController class to firstViewController. here is my code

MyCoolViewController.h// a class where data send from

@protocol MyCoolViewDelegate;

@interface M开发者_如何学PythonyCoolViewController : UIViewController  {


id <MyCoolViewDelegate> delegate;//
}
@property (nonatomic, assign) id delegate;//


@end
@protocol MyCoolViewDelegate <NSObject>//

-(void)sendAStringToAnotherView:(NSString*)string;
@end

MyCoolViewController.m

-(void)viewDidLoad{

label.text=townName;

[delegate sendAStringToAnotherView:townName];//problem is here
}




firstViewController.m  //a class where data sent
-(void)viewDidLoad{

MyCoolViewController *myViewControllerPointer=[[MyCoolViewController alloc] init];
myViewControllerPointer.delegate = self;//
}

-(void)sendAStringToAnotherView:(NSString*)string
{
//displays the string as console output
NSLog(@"plzzzzzz show data%@",string);
}

it nothing. Please help


First issue with the sample code:

NSLog(@"plzzzzzz show data",string);

should be:

NSLog(@"plzzzzzz show data: %@", string);

What is missing is ever loading MyCoolViewController. Just creating it is not enough. There is going to have to be a similarly named nib or a loadView method.

You can force loading (for testing only) in firstViewController viewDidLoad with something like this:

[[self.view addSubview:self.myViewControllerPointer.view];

2011-08-28 12:32:06.410 TestVC[25700:f203] plzzzzzz show data: this is a string

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜