0

我收到警告消息表达式中的参数是下面粗体行中的未初始化值:

***SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")***
                                                      delegate:as
                                             cancelButtonTitle:nil
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];
    as.item = [[[SHKItem alloc] init] autorelease];
    as.item.shareType = type;

有什么想法有什么问题或我该如何解决?PS - 这是在 ShareKit 中

谢谢!

Edit1:所以你是说要这样做?

+ (SHKActionSheet *)actionSheetForType:(SHKShareType)type
{
    SHKItem *myItem = [SHKItem text:@"Share"];  // See SHKItem for other convenience constructors for URL, image, text and file item types.
    SHKActionSheet *as = [SHKActionSheet actionSheetForItem:myItem];
    as.item.shareType = type;

    as.sharers = [NSMutableArray arrayWithCapacity:0];
    NSArray *favoriteSharers = [SHK favoriteSharersForType:type];

    // Add buttons for each favorite sharer
    id class;
    for(NSString *sharerId in favoriteSharers)
    {
        class = NSClassFromString(sharerId);
        if ([class canShare])
        {
            [as addButtonWithTitle: [class sharerTitle] ];
            [as.sharers addObject:sharerId];
        }
    }

    // Add More button
    [as addButtonWithTitle:SHKLocalizedString(@"More...")];

    // Add Cancel button
    [as addButtonWithTitle:SHKLocalizedString(@"Cancel")];
    as.cancelButtonIndex = as.numberOfButtons -1;

    return [as autorelease];
}

编辑2:

+ (SHKActionSheet *)actionSheetForType:(SHKShareType)type
{

    SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                      delegate:nil
                                             cancelButtonTitle:nil
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];
    as.item = [[[SHKItem alloc] init] autorelease];
    as.delegate = self;


    as.item.shareType = type;

    as.sharers = [NSMutableArray arrayWithCapacity:0];
    NSArray *favoriteSharers = [SHK favoriteSharersForType:type];

    // Add buttons for each favorite sharer
    id class;
    for(NSString *sharerId in favoriteSharers)
    {
        class = NSClassFromString(sharerId);
        if ([class canShare])
        {
            [as addButtonWithTitle: [class sharerTitle] ];
            [as.sharers addObject:sharerId];
        }
    }

    // Add More button
    [as addButtonWithTitle:SHKLocalizedString(@"More...")];

    // Add Cancel button
    [as addButtonWithTitle:SHKLocalizedString(@"Cancel")];
    as.cancelButtonIndex = as.numberOfButtons -1;

    return [as autorelease];
}
4

1 回答 1

2

我很确定问题出在这一行:

delegate:as

问题是您将委托设置为“as”,这是您正在初始化的操作表的名称。(因此您试图将 ref 传递给您正在初始化的对象作为其初始化程序的参数)。

而是在 alloc/init 调用上将委托设置为 nil,并在调用后显式设置委托。

SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")***
                                    delegate:nil
                                    cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                    otherButtonTitles:nil];
as.delegate = as;
as.item = [[[SHKItem alloc] init] autorelease];
as.item.shareType = type;
于 2011-08-11T01:26:44.437 回答