IB Actionsheet VS. programmed Action Sheet
Greetings all.
I am attempting to implement Nate Weinders' "ShareKit" Framework. All went well, until the final step.
I have a generic Action Button setup in Interface Builder with the name "shareBtn"
In my .h I have:
-(IBAction)shareBtn;
In my .m I setup a generic (working) UIActionSheet:
Up top I pull in the ShareKit Framework: #import "SHK.h"
For my button I have this:
-(IBAction)shareBtn {
UIActionSheet *actionsheet = [[UIActionSheet alloc]
initWithTitle:@"Which do you prefer?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Destuctive Button"
otherButtonTitles:@"Button 1", @"Button 2", @"Button 3", nil
];
[actionsheet showInView:[self view]];
[actionsheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"button %i clicked", buttonIndex );
}
That works all fine and dandy. Now, according to the instruction on ShareKit's install page, I am to place this code to make the actionsheet hook into the sharekit Framework:
- (void)myButtonHandlerAction
{
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
开发者_如何学C // Display the action sheet
[actionSheet showFromToolbar:navigationController.toolbar];
}
It seems fairly straight forward, and I played around with the syntax a bit (using self.toolbar, etc...) and I am just really struggling to grasp the concept and what I am missing. I read the iOS documentation on this, I referenced the few books I have, and did a lot of online searching.
Just hoping can see an obvious error or help guide me a bit.
Thank You.
Here is what I tried and the errors:
First Attempt
-(IBAction)shareBtn {
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromToolbar:navigationController.toolbar];
}
ERROR: 'navigationController undeclared'
///////Second Attempt///////
-(IBAction)shareBtn {
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet self.toolbar];
}
//////ERROR: 'Expected ']' before '.' token'//////////
///////Third Attempt///////
-(IBAction)shareBtn {
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet self.toolbar];
}
//////ERROR: 'Expected ']' before '.' token'//////////
///////Fourth Attempt///////
-(IBAction)shareBtn {
UIActionSheet *actionsheet = [[UIActionSheet alloc] init];
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionsheet showInView:[self view]];
[actionsheet release];
}
//////ERROR: Unused variable 'actionSheet' ////////// //////App launches, but just as the action sheet goes to pop up it crashes///////
FYI: ShareKit Install Page: [url=http://www.getsharekit.com/install/]ShareKit : Install[/url]
ALSO: I'm in the middle of reading "Big Nerd Ranch Guides - iPhone Programming" right now.
As a way too learn I try to apply some of the concepts I have been learning (some of which go a little beyond my current knowledge). I generally understand the specific errors, but am at lost of how to implement this action.
What confuses me about this actionSheet is that it works perfectly fine with the first method which I have learned. I'm now trying to expand on that knowledge by pulling in the ShareKit Framework and making that execute. It seems really straight forward and I'm just really discouraged...
Here is the ShareKit install (It says "In three easy lines of code") STEP 4: http://www.getsharekit.com/install/
I got it working!
Final Code:
-(IBAction)shareBtn {
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showInView:[self view]];
[actionSheet release];
}
What got me was a two silly things, one I didn't capitalize the "S" in actionSheet for the showInView or the release. Second was using the showInView:[self view]]; instead of .toolbar method.
Thanks, I knew just a little tip would help me debug.
精彩评论