2011-08-11 33 views
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; 

任何想法什麼是錯還是我怎麼能解決這個問題? P.S - 這是在ShareKit

謝謝!

編輯1:所以你說要這樣做?

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

回答

2

我敢肯定,問題是在這條線:

delegate:as 

的問題是要設置委託,以 '爲' 這是名你在初始化過程中的動作表。 (所以你正在嘗試將ref傳遞給正在初始化爲初始化參數的對象)。

改爲在alloc/init調用中將委託設置爲零,並在調用後明確設置委託。

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; 
+0

如果我做委託:自我我得到一個真正的警告:不兼容的指針類型發送「類」到ID類型的參數

+0

您需要實現你們班UIActionSheetDelegate方法。我只看了一下SHKActionSheet對象 - 它確實實現了UIActionSheetDelegate協議,因此將它設置爲自己的委託並不合邏輯。我將添加關於使用靜態便利方法的另一個答案(這樣我可以格式化代碼) – gamozzii

+0

請檢查我上面的edit1,並確認這是我應該做還是不做。謝謝! :D –

相關問題