Iphone IB行动表与程序化行动表
大家好 我正在尝试实现Nate Weinders的“ShareKit”框架。一切顺利,直到最后一步 我在Interface Builder中设置了一个名为“shareBtn”的通用操作按钮 在我的.h中,我有:Iphone IB行动表与程序化行动表,iphone,ios,cocoa-touch,uiactionsheet,Iphone,Ios,Cocoa Touch,Uiactionsheet,大家好 我正在尝试实现Nate Weinders的“ShareKit”框架。一切顺利,直到最后一步 我在Interface Builder中设置了一个名为“shareBtn”的通用操作按钮 在我的.h中,我有: -(IBAction)shareBtn; 在my.m中,我设置了一个通用(工作)UIActionSheet: 我将ShareKit框架拉到顶部:#导入“SHK.h” 我的按钮有: -(IBAction)shareBtn { UIActionSheet *action
-(IBAction)shareBtn;
在my.m中,我设置了一个通用(工作)UIActionSheet:
我将ShareKit框架拉到顶部:#导入“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框架中,使actionsheet挂钩:
- (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];
}
//////错误:“应在“.”标记“之前输入“]”//////////
///////第三次尝试///////
-(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];
}
//////错误:“应在“.”标记“之前输入“]”//////////
///////第四次尝试///////
-(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/]共享套件:安装[/url]
此外:
我现在正在阅读“大书呆子指南——iPhone编程”。
作为学习的一种方式,我尝试应用我一直在学习的一些概念(其中一些稍微超出我目前的知识)。我大致了解具体的错误,但不知道如何实施此操作
让我困惑的是,这张行动单与我所学的第一种方法配合得非常好。我现在正试图通过引入ShareKit框架并使其执行来扩展这些知识。这看起来很直截了当,我真的很沮丧
这是ShareKit安装(上面写着“三行简单的代码”)
步骤4:
我让它工作了
最终代码:
-(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或发行版的行动表中没有大写“S”。第二个是使用showInView:[自我查看];而不是.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 showInView:[self view]];
[actionSheet release];
}
给我带来的是两件愚蠢的事情,一件是我在showInView或发行版的行动表中没有大写“S”。第二个是使用showInView:[自我查看];而不是.toolbar方法
谢谢,我知道只要一点提示就能帮我调试。还有,如果有人看到这个。删除行:“[actionSheet release]”;如果有人看到此情况,也可以删除行:“[actionSheet release]”;