I want to send a image to next scent.but failed.
here is my code
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"prepareForSegue start");
NSLog(#"count is %d",count);
//bigStyle1 is a NSArray,full of UIImage
//bigImage is a UIImageView outlet
if ([bigStyle1 objectAtIndex:count]==nil) {
NSLog(#"no array image");
}
viewController3.bigImage.image=[bigStyle1 objectAtIndex:count];
if (viewController3.bigImage.image==nil) {
NSLog(#"no controller image");
}
NSLog(#"secondToThird");
NSLog(#"prepareForSegue end");
}
here is Xcode's log
2013-03-12 15:15:38.683 animation[1876:f803] prepareForSegue start
2013-03-12 15:15:50.825 animation[1876:f803] count is 0
2013-03-12 15:17:10.829 animation[1876:f803] no controller image
It seems that the problem is in assignment of image.Why assignment failed?
UPDATE
viewController3 isn't nil.But bigImage is nil.I don't know why.I actually connect bigImage to the image view
I suspect that you intend viewController3 to be the destination of the segue. In that case, you should be setting it like this:
viewController3 = segue.destinationViewController;
I further suspect that viewController3.bigImage is a UIImageView. If so, you have a problem because viewController3 hasn't loaded its view hierarchy by the time the system sends prepareForSegue:sender:, so viewController3.bigImage hasn't been set yet. It's nil, and setting a property on nil does nothing (with no warning or error message).
It would be better to give viewController3 an image property directly, and store the image on that property. Then, in viewController3's viewDidLoad method, copy the image from that property to self.bigImage.image.
Alternatively, you can cheese it by forcing viewController3 to load its view in prepareForSegue:sender: just by asking it for its view:
[viewController3 view]; // forces it to load its view hierarchy if necessary
viewController3.bigImage.image = [bigStyle1 objectAtIndex:count];
Related
I am trying to pass a string value namely,'_passedDataDate' from a viewController to a TableView Controller. And there in the TableViewController,I am trying to keep it in a array namely,'_dateArray'. while trying to do so, at first a nil object gets inserted and then the real object. how to avoid this nil value getting added?
Here is the code bellow,
- (void)viewDidLoad {
[super viewDidLoad];
_dateArray = [[NSMutableArray alloc] init];
_dateString = _passedDataDate;
if(_dateString){
[_dateArray addObject:_passedDataDate];
NSLog(#"Added Passed Data");
NSLog(#"%ld",[_dateArray count]);
}
else{
NSLog(#"No object Added");
NSLog(#"%ld",[_dateArray count]);
}
}
Output is as follow:
No object Added
0
Added Passed Data
1
Why No object Added is getting printed? I do not want it what shall Ido about it?
Also,I get the below warning,
Warning: Attempt to present on whose view is not in the window hierarchy!
Don't use Segue inside the button action.
Hide the segue
[self performSegueWithIdentifier:#"pass" sender:nil];
And try this :
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString: #"pass"])
{
TableViewController *tableView = [segue destinationViewController];
tableView.passedDataDate = #"HAI";tableView.passedDataDestination = #"Hellio";
}
}
I found a really good walk through of how to pass string values back from a ViewController to a calling ViewController and got it working perfectly. The example is really very good.
https://www.youtube.com/watch?v=YVikeoR3gYg
That said, the technique for passing back content seems relatively straight forward now that I have seen it, even if it's not that intuitive.
The example code however only includes two controllers. When I replicated the code using a much more detailed Storyboard, the code simply doesn't work. In my test app, I even embedded the calling Controller inside a NavigationController to see whether this would have an affect, but it still continued to work fine.
In my application, the ViewController is embedded within a NavigationController that is called via a SWRevealController segue class. I don't know if this is important or relevant but I am mentioning it.
I then call a CollectionViewController to choose an icon that should be passed back to the calling ViewController.
When I select the icon, I correctly identify the icon and pop
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
selectedIcon = [placeIcons objectAtIndex:indexPath.row];
NSLog(#"In IconCollectionViewControlled - selected %#", selectedIcon);
NSString *itemToPassBack = #"12345"; // Just testing any old string here...
// [self.delegate passBackIcon:selectedIcon]; // commenting out while testing
[self.delegate passBackIcon:itemToPassBack];
[self.navigationController popViewControllerAnimated:YES];
}
I get a correct trace suggesting that the right icon is selected. I would then expect that the text '12345' would be passed back to the calling Controller.
In my calling Controller, I have the following:
- (void)passBackIcon:(NSString *)iconName {
NSLog(#"Icon to use is %#", iconName);
}
But this just isn't being called at all (or at least I'm not seeing the NSLog being shown. It's just being ignored.
The delegate is being correctly declared as far as I can tell.
Am I missing something?
assuming you are working with segues, in the method prepareSegue you should setting the delegate
for Example :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"YOUR_SEGUE_IDENTIFIER"] ) {
DestinationVc *vc = (DestinationVc *)segue.destinationViewController;
[vc setDelegate:self];
}
}
Hope it works for you
I've found this to be the easiest way to pass string and other information around using a tableView.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ViewControllerYouWantToPassToo *result = [self.storyboard instantiateViewControllerWithIdentifier:#"NameOfTheViewController"];
result.stringName = #"12345" // String Name is a NSString property you set up in the ViewController you want to pass too
[self.navigationController pushViewController:result animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
I suggest you wrapping your delegate in a check to see that it is valid and that it has adopted the respective method (if optional).
if(self.delegate && [self.delegate respondsToSelector:#selector(passBackIcon:)]){
[self.delegate passBackIcon:itemToPassBack];
}else{
NSLog(#"Your delegate is not setup correctly");
}
If it enters the else, you have not set the delegate properly..ie you likely never did
self.delegate = SomeInstanceOfAClassThatAdoptsYourDelegate;
I have two view controllers: CropImageViewController and ImageCropperViewController
In CropImageViewController I have this method:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"prepareForSegue called");
if([segue.identifier isEqualToString:#"goBack"])
{
NSLog(#"processedText = %#",self.processedText);
[segue.destinationViewController setProcessedText:self.processedText];
}
}
Then, in ImageCropperViewController, I have this:
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"view will appear called");
//self.processedImageLabel.text = self.processedText;
NSLog(#"processedText = %#",self.processedText);
NSLog(#"testLabel: %#",self.testField.text);
}
This is the console output. For some reason, "processedText" is always NULL no matter what.
2014-05-23 16:51:43.488 ImageCropper[9294:60b] prepareForSegue called
2014-05-23 16:51:43.490 ImageCropper[9294:60b] processedText = E33
===..., ____
2014-05-23 16:51:43.493 ImageCropper[9294:60b] view will appear called
2014-05-23 16:51:43.494 ImageCropper[9294:60b] processedText = (null)
I see your segue "goBack". Are you come back after pushed CropImageViewController from ImageCropperViewController?
So in this case you shouldn't use a segue. You should write an IBAction for your button (or i don't know what you have to come back) and when you press it do:
[self popViewControllerAnimated:YES];
but before this, you should call the delegate to pass the new value:
[_delegate changeProcessedText:self.processedText];
Obviously i assume that you know how implement a delegation pattern.
Another way could be use KVO, so observing from the first viewController, the processedText.text value in the second viewController.
I have very strange problem with my app. I'm using AFNetworking framework in my app. I'm loading some feed with images and onclick action open new view with detail description and big image. So I send IdPhoto to the description view, but when IdPhoto is more then 12 prepareForSegue send address in memory instead of IdPhoto value.
-(void)didSelectPhoto:(PhotoView*)sender {
//photo selected - show it full screen
[self performSegueWithIdentifier:#"ShowPhoto" sender:[NSNumber numberWithInt:sender.tag]];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([#"ShowPhoto" compare: segue.identifier]==NSOrderedSame) {
DescrController* streamPhotoScreen = segue.destinationViewController;
streamPhotoScreen.IdPhoto = sender;
}
}
part of PhotoView code
-(id)initWithIndex:(int)i andData:(NSDictionary*)data {
self = [super init];
if (self !=nil) {
//initialize
self.tag = [[data objectForKey:#"IdPhoto"] intValue];
so I couldn't understand why it doesn't send IdPhoto to another View when the value more then 12
Did you set your property streamPhotoScreen.IdPhoto as STRONG ? and be sure this is not a IBOutlet.
if 1. is ok, can you put a breakpoint in your prepareForSegue: to check if sender is really what you are waiting for...
I think you need to upcast/downcast(sender) to be appropriate for streamPhotoScreen.IdPhoto.
I have a container view, which uses a storyboard embed segue to load an embedded static table view. The segue ID is 'CONTAINER'.
When I run the following code, the prepareForSegue never actually gets called so no data is passed from the parent to the child.
- (void)viewDidLoad {
[super viewDidLoad];
if ([sGender isEqualToString:#"MALE"]) {
containerGender = #"MALE";
if ([containerGender isEqualToString:#"MALE"]){
NSLog(#"MALE");
}else{
NSLog(#"BROKEN");
}
}
else if ([sGender isEqualToString:#"FEMALE"]) {
containerGender = #"FEMALE";
}
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"CONTAINER"]) {
if([containerGender isEqualToString:#"MALE"]) {
if ([containerGender isEqualToString:#"MALE"]){
NSLog(#"MALE");
}else{
NSLog(#"BROKEN");
}
SportTableViewController *tableView = segue.destinationViewController;
tableView.sportGender = #"MALE";
}
else if ([containerGender isEqualToString:#"FEMALE"]){
SportTableViewController *tableView = segue.destinationViewController;
tableView.sportGender = #"FEMALE";
}
}
}
My question is:
a)Why is prepareForSegue not called? Does the Storyboard Embed Segue behave differently to a standard seque?
b)Is there a better way of passing data from the container view to the embedded table?
Also please ignore the messy implementation/various log tests, just my attempts to work out whats going wrong.
My question actually stems from a misunderstanding of how container views load their embedded views. Apparently, it all happens before viewDidLoad. That means my conversion of sGender into containerGender took place too late.
I fixed it by passing sGender to the embedded view directly. I had thought I'd already tried this, but yesterday was obviously a slow day ;).
you can do it..
try
in childViewController
set-
#property(nonatomic,retain)parentViewController *parent;
and
in ParentViewController set-
ChildViewController *child = [[childviewController alloc]init];
child.parent=self;
It will set your parent class in childview and you can get data through parent object in child view controller.