消息表达式中的参数是未初始化的值?

时间:2011-08-11 01:03:22

标签: ios xcode memory-leaks sharekit analyzer

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

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

任何想法是错的还是我如何解决? P.S - 这是在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];
}

EDIT2:

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

1 个答案:

答案 0 :(得分: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;