Argument in message expression is an uninitialized value?
I get the warning Argument in message expression is an uninitialized value in the bolded line开发者_如何学Go below:
***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;
Any ideas whats wrong or how I can fix it? P.S - This is in ShareKit
Thanks!
Edit1: So you're saying to do this?
+ (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];
}
I'm pretty sure the problem is on this line:
delegate:as
the problem is you are setting delegate to 'as' which is the name of the action sheet you are in the process of initialising. (so you are trying to pass a ref to an object you are in the process of initialising as an argument to its initialiser).
Instead set the delegate to nil on the alloc/init call and explicitly set the delegate after the call.
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;
精彩评论