views:

57

answers:

2

I have this code in the main view controller and it is working just fine and as I wanted.

loadingActionSheet = [[UIActionSheet alloc] initWithTitle:@"Posting To Twitter..."
                                                 delegate:nil
                                        cancelButtonTitle:@"Cancel"
                                   destructiveButtonTitle:nil 
                                        otherButtonTitles:nil];

[loadingActionSheet showInView:self.view];

I wanted that code to be reusable from different part of the project so I moved it in a separate file (UIView based).

The poblem that I am facing is that self.view is not available there and I don't know why because I am learning and I don't know enough to understand what I am missing.

What do I have to do/add/change to have the actionsheet shown in my current view even if that code lives somewhere else?

A: 

Do you mean something like this?:

void actionSheetShownIn(UIView *target) {
  UIActionSheet *loadingActionSheet = [[UIActionSheet alloc] initWithTitle:@"Posting To Twitter..."
                                             delegate:nil
                                    cancelButtonTitle:@"Cancel"
                               destructiveButtonTitle:nil 
                                    otherButtonTitles:nil];

  [loadingActionSheet showInView: target];
}
Frank Shearar
That might fix the code, but that doesn't address the cognitive disconnect regarding OO technologies.
bbum
:) - probably or probably not.
amok
Thanks Frank - I will try that too - I originally added a property (same as the signature that you used) and I set that property before the actionSheet was called but I start hitting the bad EXC kind of error and just on the the line of code that I posted.
amok
Yes, I half-suspected that someone would need to address what "self" was. Your answer's correct; I just aimed to get something working.
Frank Shearar
+3  A: 

Sounds like you don't quite understand Objective-C and object oriented programming yet.

self is just like this in other OO languages. That is, when executing a method, the self variable inside the method is a means of communicating with the instance of the Class or Subclass within which the method is implemented.

If the class of self does not have a view property, self.view won't compile. Even if it does have a view property, it might not be the right view!

I would suggest you read and re-read the Objective-C guide a few times (I read it once a year the first five years I was doing Cocoa development -- predecessors to Cocoa, anyway).

Once you grok Objective-C, then you need to think about how your application is put together. How all the objects are connected together, in particular. Or, more specifically, when you broke your application up into separate files, what classes do those files define and how do the instances of those classes fit together in your application?

bbum
Thans bbum to put all that together. I believe that it's the poor wording of my question that lead you think that I am totally unfamiliar with the matter. I know close to nothing OC and Cocoa however I am definitely not green of professional programming.To get back to my original problem: I enabled NSZombie and I found out what was causing the original issue. Which invalidated any of my previous attempts to pass over the current view to the subclass of the object that I put together for the tweets.
amok