Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 6-UIActivityViewController项目_Ios_Objective C_Ios6_Uiactivityviewcontroller - Fatal编程技术网

iOS 6-UIActivityViewController项目

iOS 6-UIActivityViewController项目,ios,objective-c,ios6,uiactivityviewcontroller,Ios,Objective C,Ios6,Uiactivityviewcontroller,希望大家都知道iOS 6包含了新样式的ActionSheet(UIActivityViewController)。可以使用字符串、url、图像等参数启动UIActivityViewController。下面是相关的代码段(其中项是一个带有字符串和url参数的数组) 但是,当我们选择邮件、Facebook或Twitter等不同的股票期权时,有没有办法分配不同的参数 一种方法是我们可以实现UIActivityItemSource,在这里我们需要实现源方法 - (id)activityViewCont

希望大家都知道iOS 6包含了新样式的
ActionSheet(UIActivityViewController)。
可以使用字符串、url、图像等参数启动
UIActivityViewController
。下面是相关的代码段(其中项是一个带有字符串和url参数的数组)

但是,当我们选择邮件、Facebook或Twitter等不同的股票期权时,有没有办法分配不同的参数

一种方法是我们可以实现UIActivityItemSource,在这里我们需要实现源方法

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
它总是返回一个字符串值。但是我需要传递一个数组,这样我就可以分配各种参数,比如URL、图像和标题


您知道我们如何实现这一点吗?

您无法更改内置iOS UIActivityViewController项的任何内容,如邮件、Facebook和Twitter。为了为UIActivityViewController中的项目实现自定义操作,必须为所需的每个自定义活动创建UIActivity的自定义子类。以下是一个例子:

- (UIActivityViewController *)getActivityViewController {
    MyFeedbackActivity *feedbackActivity = [[MyFeedbackActivity alloc] init];
    MyFacebookActivity *facebookActivity = [[MyFacebookActivity alloc] init];
    MyMailActivity *mailActivity = [[MyMailActivity alloc] init];

    NSArray *applicationActivities = @[feedbackActivity, facebookActivity, mailActivity];
    NSArray *activitiesItems = @[@"A string to be used for MyFeedbackActivity", @"A string to be used for MyFacebookActivity", @"A string to be used for MyMailActivity"];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activitiesItems applicationActivities:applicationActivities];

    // Removed un-needed activities
    activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects:
                                                     UIActivityTypeCopyToPasteboard,
                                                     UIActivityTypePostToWeibo,
                                                     UIActivityTypePostToFacebook,
                                                     UIActivityTypeSaveToCameraRoll,
                                                     UIActivityTypeCopyToPasteboard,
                                                     UIActivityTypeMail,
                                                     UIActivityTypeMessage,
                                                     UIActivityTypeAssignToContact,
                                                     nil];

    return activityVC;
}
这是一个非常有限的子类UIActivity示例,其中包含有关您希望重写以处理自定义数据/操作的方法的文档

#import "MyFeedbackActivity.h"

@implementation MyFeedbackActivity

- (NSString *)activityType {
    return @"MyFeedbackActivity";
}

- (NSString *)activityTitle {
    return @"Feedback";
}

- (UIImage *)activityImage {
    return [UIImage imageNamed:@"feedback"];
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
    return YES;
}

- (UIViewController *)activityViewController {
    /**
     * DESCRIPTION:
     * Returns the view controller to present to the user.
     * Subclasses that provide additional UI using a view controller can override this method to return that view controller. If this method returns a valid object, the system presents the returned view controller modally instead of calling the performActivity method.
     * Your custom view controller should provide a view with your custom UI and should handle any user interactions inside those views. Upon completing the activity, do not dismiss the view controller yourself. Instead, call the activityDidFinish: method and let the system dismiss it for you.
     */
}

- (void)prepareWithActivityItems:(NSArray *)activityItems {
    /**
     * DESCRIPTION:
     * Prepares your service to act on the specified data.
     * The default implementation of this method does nothing. This method is called after the user has selected your service but before your service is asked to perform its action. Subclasses should override this method and use it to store a reference to the data items in the activityItems parameter. In addition, if the implementation of your service requires displaying additional UI to the user, you can use this method to prepare your view controller object and make it available from the activityViewController method.
     */
}

-(void)performActivity {
    /**
     * DESCRIPTION:
     * Performs the service when no custom view controller is provided.
     * The default implementation of this method does nothing. If your service does not provide any custom UI using the activityViewController method, override this method and use it to perform the activity. Your activity must operate on the data items received in the prepareWithActivityItems: method.
     * This method is called on your app’s main thread. If your app can complete the activity quickly on the main thread, do so and call the activityDidFinish: method when it is done. If performing the activity might take some time, use this method to start the work in the background and then exit without calling activityDidFinish: from this method. Instead, call activityDidFinish: from your background thread after the actual work has been completed.
     */
}

@end

是的,所以,如果你要否决一个答案,至少要有礼貌地解释一下原因。否则,有什么意义?
#import "MyFeedbackActivity.h"

@implementation MyFeedbackActivity

- (NSString *)activityType {
    return @"MyFeedbackActivity";
}

- (NSString *)activityTitle {
    return @"Feedback";
}

- (UIImage *)activityImage {
    return [UIImage imageNamed:@"feedback"];
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
    return YES;
}

- (UIViewController *)activityViewController {
    /**
     * DESCRIPTION:
     * Returns the view controller to present to the user.
     * Subclasses that provide additional UI using a view controller can override this method to return that view controller. If this method returns a valid object, the system presents the returned view controller modally instead of calling the performActivity method.
     * Your custom view controller should provide a view with your custom UI and should handle any user interactions inside those views. Upon completing the activity, do not dismiss the view controller yourself. Instead, call the activityDidFinish: method and let the system dismiss it for you.
     */
}

- (void)prepareWithActivityItems:(NSArray *)activityItems {
    /**
     * DESCRIPTION:
     * Prepares your service to act on the specified data.
     * The default implementation of this method does nothing. This method is called after the user has selected your service but before your service is asked to perform its action. Subclasses should override this method and use it to store a reference to the data items in the activityItems parameter. In addition, if the implementation of your service requires displaying additional UI to the user, you can use this method to prepare your view controller object and make it available from the activityViewController method.
     */
}

-(void)performActivity {
    /**
     * DESCRIPTION:
     * Performs the service when no custom view controller is provided.
     * The default implementation of this method does nothing. If your service does not provide any custom UI using the activityViewController method, override this method and use it to perform the activity. Your activity must operate on the data items received in the prepareWithActivityItems: method.
     * This method is called on your app’s main thread. If your app can complete the activity quickly on the main thread, do so and call the activityDidFinish: method when it is done. If performing the activity might take some time, use this method to start the work in the background and then exit without calling activityDidFinish: from this method. Instead, call activityDidFinish: from your background thread after the actual work has been completed.
     */
}

@end