0

Please i am in the middle of the work that's why i couldn't repeat the whole stuff from the beginning for a simple trick. I use a view based application template and i have 2 views, the first view is my menu view, which contains 3 buttons, each buttons send me to another view, now, in these one of these "another view", i need to make a custom back button (with that shaft), i see tutorials but they use another method of work which is not useful to me.

Here is a part of my code in my first view(the menu) which concern my problem :

@implementation TopStationViewController

-(IBAction)goToAproposView  {

    aproposViewController.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
       [self presentModalViewController:aproposViewController animated:YES];

 }

and here my code in one of the second view (in which i want to make the custom back button),

   #import "AproposViewController.h"

   @implementation AproposViewController

   -(IBAction)goBackToMainMenu{

        [self dismissModalViewControllerAnimated:YES];
   }

Thanks in Advance!

Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
Malloc
  • 15,434
  • 34
  • 105
  • 192
  • i have to add that all works fine and the transition is good, all i want is to make the custom back button in AproposViewController instead of the rounded button :) – Malloc Mar 29 '11 at 08:21
  • Have you tried the answer in here: http://stackoverflow.com/questions/4260238/draw-custom-back-button-on-iphone-navigation-bar – ingh.am Mar 29 '11 at 08:21
  • i don't know where to put the code given in that answer :( – Malloc Mar 29 '11 at 08:26
  • should i think about the backBarButtonItem, if so, how can i call it and which value to assign :) – Malloc Mar 29 '11 at 08:35
  • Put it in your viewDidLoad on the view thats in your UINavigationController. Remember, we can't see all your code! – ingh.am Mar 29 '11 at 08:43
  • Try to add a screenshot or something similar to help us understand what you're trying to achieve – phi Mar 30 '11 at 18:30

2 Answers2

1

Why don't you just make a custom button that has a proper image as the background?

If you use a UINavigationController, you will need to create a custom UIButton, and then set it as the custom view for a UIBarButtonItem:

UIButton* doneButton = [[UIButton alloc] init];
[doneButton setBackgroundImage:anImageThatLooksLikeTheBackWithTheArrow forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem* doneBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
self.navigationItem.leftBarButtonItem = doneBarButtonItem;
[doneButton release];
[doneBarButtonItem release];

In any case, note that the way the original back button looks should be used for its original purpose, that is to animate the view "left" in a drill-down navigation. Maybe you want to use the default bluish "done" button instead? (I'm not saying that your app will be rejected or something of course!)

phi
  • 10,634
  • 6
  • 53
  • 88
  • @Malek : yes thats the way u can easily make back button as u like to achieve ..but the thing is that u should not do that .. that is not advisable at all .. and u never know reviewers dont like that u r using their navigation based back button for ur modal views and ur app may get rejected – Iphone_bharat Mar 29 '11 at 09:37
  • I cannot see why the app will be rejected. Any official apple doc said that? – AechoLiu Mar 29 '11 at 09:41
  • You can do this (and you wont get rejected for it). It won't look great unless its part of your app design. Look at the answer on here stackoverflow.com/questions/4260238 for creating a true back button!! – ingh.am Mar 29 '11 at 10:18
  • i'm struggling and i still have no solution, actually i can do it with windowbased application template but this is not my project template, i use view based application. – Malloc Mar 29 '11 at 23:28
  • i search more and more and i have noticed that i can't do the custom back button without using UINavigationController, what is causing me trouble is that UINavigationControler add the blue bar at the top of the view which is not in my project requiremets :) i just need if i can do something else to make it :) – Malloc Mar 30 '11 at 00:05
  • Can you post a quick sketch image of what you want to achieve? – phi Mar 30 '11 at 07:50
0

You might be looking for a delegate method.

Take a look at this question for a guide, that also includes data transfer: Delegate with data transfer

Community
  • 1
  • 1
Qiau
  • 5,976
  • 3
  • 29
  • 40