我在UIActionSheet中有一个UIPickerView,并且在SO的许多其他人建议的方式做到了这一点:
如何在UIActionSheet中添加UIPickerView
直到现在,在iOS 7上测试我的应用程序时,这些解决方案运行良好.它仍然有效,但在Xcode的运行时期间我收到了很多"无效的上下文0x0"警告.
这些错误也带来了一个很好的消息:
CGContextSetFillColorWithColor:无效的上下文0x0.这是一个严重的错误.该应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降低.此通知是礼貌的:请解决此问题.它将成为即将到来的更新中的致命错误.
可能是Apple最终想要停止这种解决方案,还是我们可以解决或修复的问题?
在iOS 8之前,我们不得不使用UIAlertView和UIActionSheet
我们不允许在它们上面混淆视图层次结构或子类.
UIAlertView类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.
UIActionSheet不是设计为子类,也不应该为其层次结构添加视图.如果您需要提供比UIActionSheet API提供的更多自定义的工作表,您可以创建自己的工作表并使用presentViewController以模态方式呈现它:animated:completion:.
然而,iOS8 Apple已经推出UIAlertController了更换两者UIAlertView和UIActionSheet(请查看此处的预发布文档).
因此,在这个预发布文档中,没有任何关于无法子类化或更改视图层次结构,它甚至有这种方法,addTextFieldWithConfigurationHandler:因此我们能够更改视图层次和/或子类,UIAlertController而不必担心Apple是否会批准或拒绝我们的应用程序?
现在iOS8上的过时UIActionsheet和UIAlertview定制上iOS7工作不发生作用了.到目前为止,我所知道的唯一定制是色彩.我需要的是改变标题的字体大小和样式,我没有找到任何方式使用新的UIAlertAction.
已经提到了这个,但我仍然希望有一种方法可以至少改变标题大小和字体.
为您提供我的一些代码 UIAlertAction
UIAlertController * alertActionSheetController = [UIAlertController alertControllerWithTitle:@"Settings"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * aboutTheAppAction = [UIAlertAction actionWithTitle:@"About the App"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
NSLog(@"About the app");
[self openAbout];
}];
[alertActionSheetController addAction:aboutTheAppAction];
[self presentViewController:alertActionSheetController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud) 当我使用UIActionSheet或UIAlertController执行以下操作时,我在模拟器中看到iOS 8中的内存泄漏.UIActionSheet在IOS 8中使用UIAlertController,因此问题是相关的.
按下按钮时会调用showCameraAction.我已从委托方法中删除了所有内容,但在下面显示的情况下仍然会出现泄漏.我是否以某种方式使用UIActionSheet,我不应该这样做?我将非常感谢您解决此问题的任何帮助.相同的代码与IOS 7没有泄漏(在模拟器中).
-(IBAction)showCameraAction:(id)sender
{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Photo From:"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Phone", @"Flickr", nil];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
//also tried just showInView: self.view
}
Run Code Online (Sandbox Code Playgroud)
//空
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
}
Run Code Online (Sandbox Code Playgroud)
也尝试使用UIAlertController,结果相同:
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Photo From:"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *phoneAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Phone", @"Phone action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Phone action");
}];
UIAlertAction *flickrAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Flickr", @"Flickr action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Flickr action");
}];
[alertController addAction:phoneAction];
[alertController addAction:flickrAction];
[self presentViewController:alertController …Run Code Online (Sandbox Code Playgroud) 我使用这篇文章中的代码在我的应用程序中显示一个操作表.但它表现得像

会是什么原因?
我显示操作表的代码是
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 300, 300);
UIView *pickerView = [[UIView alloc] initWithFrame:pickerFrame];
pickerView.backgroundColor=[UIColor blackColor];
[actionSheet addSubview:pickerView];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[self.view addSubview:actionSheet];
Run Code Online (Sandbox Code Playgroud) 我有一个标题字符串为"DO:这些任务"的UIActionSheet.在标题字符串中,子字符串"DO:"应该是粗体(具有特定的字体大小),子字符串"这些任务"应该是常规的.可能吗?我怎样才能做到这一点?
我使用以下代码在我的应用程序中调用操作表共享:
- (IBAction)sendPost:(id)sender
{
NSArray *activityItems = nil;
UIImage *appIcon = [UIImage imageNamed:@"appIcon.png"];
NSString *postText = [[NSString alloc] initWithFormat:@"LETS ASSUME THIS STRING IS LONGER THAN 140 CHARACTERS THAT TWITTER PROHIBITS BUT CAN STILL BE SHARED VIA FACEBOOK, EMAIL, TEXT"];
activityItems = @[postText,appIcon];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
问题是这个:postText超过140个字符,所以不可能通过twitter分享,字符数将是-x(你通过twitter分享的红色字符数),我的问题是:怎么能我做了一个例外,以便shortPostText在选择Twitter进行共享时使用的是另一条消息吗?
一旦你sendPost发送了动作,我就看不到为twitter明确设置字符串的方法了:

编辑:我不明白为什么有人会对这个问题进行投票,我不会问如何制作if/else语句或如何编程.这是一个真正的问题,需要一个真正的答案.
更新:我需要解决这个问题,因为当用户尝试通过我的应用程序中的Twitter共享时,这是我得到的:

红色/负号字符指示符和非活动帖子按钮,因此除非字符数减少到0或更少,否则不允许帖子转到twitter.
我正在尝试为iOS 7调整我的应用程序.我遇到的问题是我无法更改某些控件的色调颜色.
我添加了
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if (IOS7_OR_LATER)
self.window.tintColor = [self greenTintColor];
Run Code Online (Sandbox Code Playgroud)
到我的应用代表的
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Run Code Online (Sandbox Code Playgroud)
它主要有所帮助,但消息框和操作表按钮的颜色仍然是默认的蓝色.
我怎样才能重新着色所有这些按钮呢?
一些截图:

我正试图在UIActionSheetiPad 上显示一个.这是我正在使用的代码:
-(void) presentMenu {
UIActionSheet *popupMenu = [[UIActionSheet alloc] initWithTitle:@"Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil];
for (NSString *option in _menuItems) {
[popupMenu addButtonWithTitle:option];
}
popupMenu.actionSheetStyle = UIActionSheetStyleBlackOpaque;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[popupMenu showFromTabBar:_appDelegate.tabBar.tabBar];
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[popupMenu showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
}
[popupMenu release];
return;
}
Run Code Online (Sandbox Code Playgroud)
该程序的iPhone版本显示所有按钮_menuItems,但iPad版本只是忽略该阵列中的最后一项.有谁知道为什么会发生这种情况?
谢谢,
Teja.
我在iPhone上有一个UIAlertController(UIAlertControllerStyleActionSheet)现在应该UIPopoverPresentationController在iPad版本上呈现..
我正在做以下事情:
UIPopoverPresentationController *popover = sectionActionSheet.popoverPresentationController;
if (popover){
popover.sourceView = self.view;
popover.barButtonItem = menuButton;
popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,popover的位置(相对于UIBarButton)并不是那么好,如果我旋转设备,弹出窗口不会重新定位:
角落不居中:
旋转后:

uiactionsheet ×10
ios ×7
objective-c ×5
iphone ×3
uialertview ×3
cocoa-touch ×2
ios8 ×2
ipad ×2
font-size ×1
ios7 ×1
memory-leaks ×1
twitter ×1
uipickerview ×1
uipopover ×1