actionSheet on startup

Discussion in 'iOS Programming' started by bytezone, May 14, 2009.

  1. bytezone macrumors member

    Joined:
    Apr 20, 2009
    #1
    I am not able to add actionSheet on start of the app.

    In the code I am dynamically creating buttions and then adding it to view. Later I am adding view as Subview to window.

    Where should I add my action sheet code....?? Also self.view is giving me error.

    UIActionSheet *options = [[UIActionSheet alloc]
    initWithTitle:mad:"HomeBrewing Styles"
    delegate:self
    cancelButtonTitle:mad:"I Can't Decide"
    destructiveButtonTitle:nil
    otherButtonTitles:mad:"English", @"American", @"Imperial", nil];
    [options setMessage:mad:"Select a Style of IPA:"];
    [options showInView:self.view]; // error is here...
    [windows addSubView:myView];
    ][window makekeyAndVisible];
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Where have you added this code?

    Also, please use the [ CODE ] tags for your code snippets (# icon in the toolbar). Makes it easier for us read.
     
  3. bytezone thread starter macrumors member

    Joined:
    Apr 20, 2009
    #3
    I added this to applicationDidFinishLaunching:(UIApplication *)application.

    Also can you elaborate on what you meant and how it can be done...
    please use the [ CODE ] tags for your code snippets ...

     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    So, in your applicationDelegate. Which means it probably doesn't have a view property (unless you defined one), so self.view isn't defined. You'll probably want to move this code into your initial view controller code. Which might be a RootViewController class.

    When composing your Reply to Thread, enclose any code snippets in
    HTML:
    [CODE] ... [/CODE]
    tags. If you look in the toolbar above the textarea you will see an icon that looks like a # symbol. This will get you started with the tags you need.
     
  5. danielpunt macrumors newbie

    Joined:
    Oct 11, 2007
    Location:
    Netherlands
    #5
    Change this:
    Code:
    [options showInView:self.view];
    Into this:
    Code:
    [options show];
    Also, I think this line is unnessacary:
    Code:
    [windows addSubView:myView];
     
  6. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #6
    note that cocoa touch is case sensitive. so "makekeyAndVisible" won't work, neither will "addSubView". also, it's "window" not "windows" - which will produce another error.

    also, if you are using this in your application delegate than it's likely to be in the wrong place. you add the actionSheet to "self.view" - what view is that? where did you create it? you should move this code to your viewController's "viewDidLoad" method.
    if you need to show it before a view is shown, then you should use "self.window" instead of "self.view" - since you want to add it to the window then, since nothing else exists.
     
  7. CocoaPuffs macrumors 68010

    Joined:
    Aug 23, 2008
    #7
    Load some plain view class and put the actionsheet code in that view class file. You shouldn't make a mess in the appdelegate file, which you will with actionsheetdelegate methods that you also have to add.
     
  8. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #8
    well, I'm not an expert programmer but I would disagree. Logically, if the actionsheet is supposed to pop up before anything is displayed (for example because the actionsheet decides which view is shown at startup) I would probably put it in the appDelegate - because that's the code that shows the initial view.
     
  9. CocoaPuffs macrumors 68010

    Joined:
    Aug 23, 2008
    #9
    Well, in a decent UI, one should expect something more than an actionview prompt when the app is loaded.
     
  10. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #10
    yeah, well, I agree but that's another story ... :D
     

Share This Page