我有一个简单的 iPad 项目,其视图有两个容器。选择左侧的条目后,右侧会更新其详细信息。右视图控制器在工具栏上也有 UIBarButtonItem,它使用 UIActivityController 在不同的社交网络上共享其内容。该按钮与 IBAction 连接如下:
-(IBAction)Share:(id)sender
{
NSArray *activityItems = @[self.title, urlString];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(@"Activity = %@",activityType);
NSLog(@"Completed Status = %d",completed);
if (completed)
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Successfully Shared" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
} else
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Unable To Share" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
}
}];
}
一切正常,但是当应用程序第一次打开时,右侧是空的,点击共享按钮会导致崩溃。
当右视图控制器为空并且仅当视图控制器中有内容时才出现条形按钮项时,如何隐藏条形按钮?
提前致谢。