更新:
我正在尝试从另一个类调用一个方法并将其放在一个if
语句中说"如果uploadPhoto
方法为true,则显示成功用于测试目的"这是我更新的代码:
PhotoScreen *script = [[PhotoScreen alloc] init];
if ([script uploadPhoto])
{
NSLog(@"Sucess!");
}
它不再给我错误但是当我从uploadPhoto方法登顶照片时,它不记录"成功"这是我的uploadPhoto方法:
- (BOOL)uploadPhoto
{
//upload the image and the title to the web service
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"upload",@"command",
UIImageJPEGRepresentation(photo.image,70),@"file",
fldTitle.text, @"title",nil]
onCompletion:^(NSDictionary *json)
{
//completion
if (![json objectForKey:@"error"])
{
//success
[[[UIAlertView alloc]initWithTitle:@"Success!"
message:@"Your photo is uploaded"
delegate:nil cancelButtonTitle:@"Yay!"
otherButtonTitles: nil] show];
}
else
{
//error, check for expired session and if so - authorize the user
NSString* errorMsg = [json objectForKey:@"error"];
[UIAlertView error:errorMsg];
if ([@"Authorization required" compare:errorMsg]==NSOrderedSame)
{
[self performSegueWithIdentifier:@"ShowLogin" sender:nil];
}
}
}];
return YES;
}
我做错了什么?
答案 0 :(得分:1)
您需要返回BOOL
方法。在您的方法中,如果方法成功,则应该在某处使用语句return YES;
,如果失败则在return NO;
。您可以将代码修改为以下内容:
PhotoScreen *script = [[PhotoScreen alloc] init];
if ([script uploadPhoto])
{
NSLog(@"Sucess!");
}
重复的方法调用与比较一样是不必要的。