accessing instance of a view from another class?
I have been trying to do this for a long time now. so here is what I am doing
firstviewcontroller
.hiPhoneStreamingPlayerViewcontroller *viewController;
@property(nonatomic,retain)iPhoneStreamingPlayerViewController *viewController;
.m
in didselectrowatindexpath BooksNavController *bks = [[BooksNavController alloc]init];
bookDetailViewController.title = [NSString stringWithFormat:@"%@",[booksArray objectAtIndex:rowSelected]];
NSString *ti = [NSString stringWithFormat:@"%@",[booksArray objectAtIndex:rowSelected]];
[bookDetailViewController title3:ti];
Music_appAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.booksNavController pushViewController:bookDetailViewController animated:YES];
[bks nowPlayingView:bookDetailViewController];
NSString *check = [NSString stringWithFormat:@"%@",[urlArray objectAtIndex:rowSelected]];
[bookDetailViewController check:check];
[bks release];
now in secondviewcontroller
in didselectrowatindexpath (is a tableview again)
if (self.bookDetailViewController == nil)
{
iPhoneStreamingPlayerViewController *aBookDetail = [[iPhoneStreamingPlayerViewController alloc] initWithNibName:@"iPhoneStreamingPlayerView" bundle:nil];
self.bookDetailViewController = aBookDetail;
[aBookDetail release];
}
BooksNavController *bks = [[BooksNavController alloc]init];
bookDetailViewController.title = [NSString stringWithFormat:@"%@",[booksArray objectAtIndex:rowSelected]];
NSString *ti = [NSString stringWithFormat:@"%@",[book开发者_高级运维sArray objectAtIndex:rowSelected]];
[bookDetailViewController title3:ti];
Music_appAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.booksNavController pushViewController:bookDetailViewController animated:YES];
[bks nowPlayingView:bookDetailViewController];
NSString *check = [NSString stringWithFormat:@"%@",[urlArray objectAtIndex:rowSelected]];
[bookDetailViewController check:check];
[bks release];
PlaylistTableViewController *playlistTableViewController = [[PlaylistTableViewController alloc]init];
[playlistTableViewController checkView:2];
playlistTableViewController.bookDetailViewController1 = bookDetailViewController;
[playlistTableViewController release];
This isn't working though the view is being set to nil for some reason I don't know why (I have made a property for the view too).
you can do like below:
Below is an idea for how to achieve you condition.
Suppose, you have 2 view controller.
FirstViewController
SecondViewController
Now, Create one variable in SecondViewController.h file id parent;
And create one method:
-(void)setParent:(id)pParent;
in SecondViewController.m file
implement method like below
-(void)setParent:(id)pParent{
parent=pParent
}
Now, you have one object of SecondViewController in FirstViewController.
Suppose it's name is objSecondViewController.
After pushing to the secondViewController call "setParent" method.
Like [objSecondViewController setParent:self];
That's it. Now, if you want to call any method of FirstViewController,
then you can do it using "parent" object.
One thing, import "FirstViewController.h" in you "SecondViewController.m" file.
Hope you got the point and it will be helpful to you.
You'll need to set up a delagate method or even better still(and more simple), check out NSNotificationCenter. It will do the job by passing a method from one view controller to another and you can link an action to it.
精彩评论