IB 行动表 VS.编程行动表

发布于 2024-10-19 09:12:17 字数 4361 浏览 1 评论 0原文

大家好。

我正在尝试实现 Nate Weinders 的“ShareKit”框架。一切都很顺利,直到最后一步。

我在 Interface Builder 中设置了一个名为“shareBtn”的通用操作按钮

在我的 .h 中,我有:

-(IBAction)shareBtn;

在我的 .m 中,我设置了一个通用(工作)UIActionSheet:

在顶部,我引入了 ShareKit 框架: #import "SHK. h"

对于我的按钮,我有这个:

 -(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 );
}

效果很好。现在,根据 ShareKit 安装页面上的说明,我将放置此代码以使操作表挂钩到 sharekit 框架中:

- (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];

    // Display the action sheet
    [actionSheet showFromToolbar:navigationController.toolbar];
}

它看起来相当简单,并且我稍微尝试了一下语法(使用 self.toolbar 等)。 ..)我真的很难理解这个概念以及我所缺少的东西。我阅读了这方面的 iOS 文档,参考了我拥有的几本书,并进行了大量的在线搜索。

只是希望能看到明显的错误或帮助指导我。

谢谢。

这是我尝试过的方法和错误:

第一次尝试

 -(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];
}

错误:'navigationController未声明'

//////第二次尝试////////////

 -(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];
}

错误:'在'.'之前预期']'令牌'//////////

///////第三次尝试///////

 -(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];
}

//////错误:'在'.'之前需要']'令牌'//////////

///////第四次尝试///////

-(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];
}

//////错误:未使用的变量'actionSheet' ///////// / //////应用程序启动,但当操作表弹出时它崩溃了///////

仅供参考:ShareKit 安装页面:[url=http://www.getsharekit.com/install/] ShareKit:安装[/url]

另外: 我现在正在阅读《Big Nerd Ranch 指南 - iPhone 编程》。

作为一种学习方式,我尝试应用我一直在学习的一些概念(其中一些概念超出了我目前的知识范围)。我通常了解具体错误,但不知道如何实施此操作。

这个actionSheet 令我困惑的是它与我学到的第一种方法完美配合。我现在正尝试通过引入 ShareKit 框架并使其执行来扩展这些知识。这看起来真的很简单,我真的很沮丧......

这是 ShareKit 安装(它说“用三行简单的代码”) 第 4 步: http://www.getsharekit.com/install/

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];

    // 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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-10-26 09:12:17

我成功了!

最终代码:

-(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];
}

令我困惑的是两件愚蠢的事情,一是我没有在 showInView 或发布的 actionSheet 中将“S”大写。其次是使用 showInView:[self view]];而不是 .toolbar 方法。

谢谢,我知道一点点提示就能帮助我调试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文