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];
}
如果我做委託:自我我得到一個真正的警告:不兼容的指針類型發送「類」到ID類型的參數 –
您需要實現你們班UIActionSheetDelegate方法。我只看了一下SHKActionSheet對象 - 它確實實現了UIActionSheetDelegate協議,因此將它設置爲自己的委託並不合邏輯。我將添加關於使用靜態便利方法的另一個答案(這樣我可以格式化代碼) – gamozzii
請檢查我上面的edit1,並確認這是我應該做還是不做。謝謝! :D –