Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3400772
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:56:02+00:00 2026-05-18T04:56:02+00:00

I’m trying to reuse code, I have some tutorial view controllers / views, which

  • 0

I’m trying to reuse code, I have some tutorial view controllers / views, which I would like to call from an action sheet. However, the calling views are different. Sometimes the tutorial view(s) would need to be added as a subview and sometimes they would be added to the navigation controller.

How can I expand my standard function to cater for these two different situations ?

You can see what I’m having to do instead, which means duplicate code 🙁

I have a class called which holds the standard code, I want to add calls to views here directly.

-(void)showHelpClickButtonAtIndex:(int)buttonIndex:(UIView *)vw {
if (buttonIndex == CommonUIHelpPagesBtnIdx) {
    // do nothing
} else if (buttonIndex == 0) {
    NSLog(@"Tutorial here");
}
}

I use in one view like this …

- (void)actionSheet:(UIActionSheet *)actionSheet 
      clickedButtonAtIndex:(NSInteger)buttonIndex {
CommonUI *cui = [CommonUI alloc];
[cui showHelpClickButtonAtIndex:buttonIndex:self.view];
[cui release];

if (buttonIndex == CommonUIHelpPagesBtnIdx) {
    UIViewController *theController = [[HelpViewController alloc] 
         initWithNibName:@"HelpView" 
         bundle:nil onPage:HelpPageCalcBalance];
    [self.navigationController.topViewController 
         presentModalViewController:theController animated:YES];
    [theController release];
   }
}

And is another view like this…

- (void)actionSheet:(UIActionSheet *)actionSheet 
     clickedButtonAtIndex:(NSInteger)buttonIndex {
   [cui showHelpClickButtonAtIndex:buttonIndex:self.view];

   if (buttonIndex == CommonUIHelpPagesBtnIdx) {
        theController = [[HelpViewController alloc] initWithNibName:@"HelpView"                     
        bundle:nil onPage:HelpPageGettingStarted];

        [self.view addSubview:theController.view];
   }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:56:02+00:00Added an answer on May 18, 2026 at 4:56 am

    Maybe the actionSheets could share one same delegate that would be a root viewController or the appDelegate that would know what to do according to it’s current state. Hence the same actionSheet method would be used in both case.

    If you put your appDelegate which can always be reached as the actionSheetDelegate, you should be able to gain control on every way to present your view, either modally or not in any of your views + the window.

    EDIT (re-Edited with your code): Maybe try this

    MyAppDelegate.h:

    @interface MyAppAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate>
    (...)
    
    - (void) showHelp;
    

    MyAppDelegate.m:

    - (void) showHelp {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" 
                                                                 delegate:self
                                                        cancelButtonTitle:@"Cancel" 
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles: @"Tutorial", @"Help Pages", nil];
    
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [actionSheet showInView:window];
        [actionSheet release];
    }
    
    - (void)actionSheet:(UIActionSheet *)actionSheet
    clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == CommonUIHelpPagesBtnIdx) {
            UIViewController *theController = [HelpViewController alloc];
            if ([[self lvc] superview] != nil) {
                theController = [initWithNibName:@"HelpView"                     
                                          bundle:nil
                                          onPage:HelpPageGettingStarted];
                [window addSubview:theController.view];
            } else {
                theController = [initWithNibName:@"HelpView"
                                          bundle:nil
                                          onPage:HelpPageCalcBalance];
                UINavigationController * navController = [tabBarController selectedViewController];
                [navController.topViewController presentModalViewController:theController animated:YES];
            }
            [theController release];
        }
    }
    

    and in your viewControllers:

    - (void)viewDidLoad {
        [super viewDidLoad];
        MyAppDelegate *delegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
    
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
        [infoButton addTarget:delegate
                       action:@selector(showHelp)
             forControlEvents:UIControlEventTouchUpInside];
         UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
         self.navigationItem.rightBarButtonItem = infoItem;
         [infoItem release];
     }
    

    Didn’t try it but it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.