我正在使用UIPrintInteractionController从rect中呈现它.
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
// than set printing settings
...
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[controller presentFromRect:rect inView:view animated:YES completionHandler:completionHandler];
Run Code Online (Sandbox Code Playgroud)
比我设置页数(> 1)并选择一台打印机.在设备旋转之前我打电话
[controller dismissAnimated:animated];
根据Xcode文档: You should dismiss the printing options when they are presented in a sheet or animated from a rectangle and the user changes the orientation of the device.
当我UIPrintInteractionController在旋转后出现时,打印份数被设置回1(如在初始视图中),而打印机保持选中状态.UIPrintInfo的Ivar _copies是私有的,所以我无法在旋转期间获取它并存储.
如何在旋转后恢复打印页数?
我UIScrollView和另一个UIScrollView里面有一个.它们都是水平滚动的pagingEnabled = YES.假设我开始滚动内部滚动视图并达到最右边界限.如果我继续滚动它,那么外部scrollView开始移动.我需要避免这种情况.内视图应该带有橡皮筋效果,外部应该留在它的位置.
希望它很清楚,但这是一个草图:

我试着outerView.scrollEnabled = NO;像这样设置:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
outerView.scrollEnabled = NO;
}
Run Code Online (Sandbox Code Playgroud)
如果只在innerView中滚动它,它正是我需要的.OuterView不再滚动.但是scrollEnabled如果我想要再次滚动outerView,我必须在某处重新设置YES.我试过这里做的:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
outerView.scrollEnabled = YES;
}
Run Code Online (Sandbox Code Playgroud)
,但是我得到了同样的问题:在达到内部视图外部滚动的最右边界之后,而不是使用橡皮筋效果的内部跳跃.
有什么建议如何解决问题?
我在我的项目中使用Xcode 5和autolayout.我有一个.xib文件,它们之间有很多子视图和约束.现在我需要创建一个中间全屏容器视图并将所有子视图放在那里.所以现在我有了view->subviews,我想要view->container view->subviews.当我在IB中通过将子视图拖动到容器视图中来执行此操作时,它们都会居中并且所有约束都会丢失.手动恢复所有约束会有点困难.是否有一种明智的方法可以保持所有子视图的位置和约束?
我遇到以下问题:每当我将播放和录制类别设置为我的应用程序中的音频会话时,AirPlay就不可用:
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayAndRecord
error: &setCategoryError];
Run Code Online (Sandbox Code Playgroud)
此调用使AirPlay消失并立即将音频重新路由到扬声器.
问题可以很容易地重现,例如在avTouchXcode文档中的示例项目中,通过用以下AVAudioSessionCategoryPlayback类别替换类别 AVAudioSessionCategoryPlayAndRecord:在原始示例中,AirPlay选择器是可见的并允许更改输出源,而AVAudioSessionCategoryPlayAndRecord选择器类别则消失.
有没有正确的方法切换到AVAudioSessionCategoryPlayAndRecord类别,以便AirPlay仍然可用?
(这样的问题已经被问到,但没有得到任何答案.)
我有两个NSDictionaries含有NSStrings.为了比较这两个词典我使用isEqualToDictionary:方法.关于isEqualToDictionary:说的文件
"如果两个词典各自拥有相同数量的条目,则两个词典具有相同的内容;对于给定的键,每个词典中的相应值对象满足isEqual:test."
所以,我的字符串通过isEqual:方法进行比较.
问题是:
如何isEqual:为此工作NSString?
是否使用isEqual:从NSObject?我读过,isEqual从NSObject仅使用比较地址==.为了证明或反驳这个想法,我写了一个样本:
NSString *str1 = @"sampleString";
NSString *str2 = [NSString stringWithFormat:@"%@", @"sampleString"];
BOOL result = [str1 isEqual:str2];
Run Code Online (Sandbox Code Playgroud)
的result是YES,的地址str1和str2是不同的东西.
所以,要么它不使用isEqual:来自NSObject(还有什么比?),或者NSObject的isEqual:做一些更复杂的然后就检查地址的平等.
有谁知道它是如何工作的?
我在我的项目中发现了一个有趣的代码,我想知道它是如何工作的.如果我简化它,在游乐场看起来像这样:
var b: Bool = true
var n: NSNumber = b as NSNumber
Run Code Online (Sandbox Code Playgroud)
我不明白为什么as运营商投Bool了NSNumber.文档as给出了使用它的唯一示例,即用于检查数组中元素的类型[Any].这是Docs的一个例子,这就是我期望的as用法:
var things = [Any]()
for thing in things {
switch thing {
case 0 as Int:
case 0 as Double:
Run Code Online (Sandbox Code Playgroud)
我没想到as会做一个真正的演员.我在哪里可以阅读更多相关信息?当我尝试类似的代码Int代替NSNumber,它不会编译:
var b: Bool = true
var n: Int = b as Int --> doesn't compile
Run Code Online (Sandbox Code Playgroud)
那NSNumber似乎是一个特例?我糊涂了.任何人都可以阐明这一点吗?
我UIPopoverController用UITableViewController它的内容视图控制器打开popover .
Popover具有合适的大小,乍一看它的内容视图调整正确,但如果我尝试在弹出窗口内滚动,它会滚动,但不应该.似乎在 - (void)viewDidAppear(图1,2)之后内容视图变得大约高20 px.我该怎么做来检查尺寸:
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"%@", self.view);
}
Run Code Online (Sandbox Code Playgroud)
输出是
Popovers[3016:c07] <UITableView: 0x10b80600; frame = (0 0; 200 66); autoresize = W+H; gestureRecognizers = <NSArray: 0x1004cc20>; layer = <CALayer: 0x1004c4a0>; contentOffset: {0, 0}>
Run Code Online (Sandbox Code Playgroud)
此时大小正确,它等于弹出窗口的大小.打开popover后,它的内部大小没有边距为66像素(在标尺应用程序的帮助下测量).因此,它似乎应该完全适合内容视图的大小.但意外的垂直滚动以某种方式出现.
比如果我将40 px添加到popover的高度,
[mOptionPopoverController setPopoverContentSize:(CGSize){200, 86}];
它的内容视图也会增加并且符合预期,没有任何滚动条.唯一的问题是我不需要在popover底部空20 px(图3).
我做了一个小测试项目来重现我的问题.这是重要的代码:
@implementation ViewController
- (IBAction)buttonPressed:(id)sender
{
TableViewController *popoverViewController = [[TableViewController alloc] initWithStyle:UITableViewStyleGrouped];
UIPopoverController* mOptionPopoverController = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
[mOptionPopoverController setPopoverContentSize:(CGSize){200, 66}];
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
[mOptionPopoverController presentPopoverFromRect:popoverRect inView:self.view …Run Code Online (Sandbox Code Playgroud) 我的项目中有几个不同的枚举,符合相同的协议.compareEnumType协议中的方法比较忽略关联值的枚举案例.这是我在游乐场的代码:
protocol EquatableEnumType {
static func compareEnumType(lhs: Self, rhs: Self) -> Bool
}
enum MyEnum: EquatableEnumType {
case A(Int)
case B
static func compareEnumType(lhs: MyEnum, rhs: MyEnum) -> Bool {
switch (lhs, rhs) {
case (.A, .A): return true
case (.B, .B): return true
default: return false
}
}
}
enum MyEnum2: EquatableEnumType {
case X(String)
case Y
static func compareEnumType(lhs: MyEnum2, rhs: MyEnum2) -> Bool {
switch (lhs, rhs) {
case (.X, .X): return true
case (.Y, …Run Code Online (Sandbox Code Playgroud) 我正在构建没有.xib文件的视图,只是使用loadView方法.但在这一点上,当调用loadView时,视图框架尚不清楚.所以,我只是用它来构建没有具体框架的视图层次结构.(比我更新视图的布局时,它的框架是已知的)的问题是:我应该使用[[UIView alloc] init]或者[[UIView alloc] initWithFrame:CGRectZero]也可以是别的东西,初始化视图,而不知道帧?这是代码:
- (void)loadView
{
UIView *containerView = [[UIView alloc] init];
// or
// UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
// or something else?
// ...
self.view = containerView;
[containerView release];
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用 MapKit 的应用程序。
我在调整地图大小后计算当前缩放。
通过定义(来自MKGeometry.h文件)
MKZoomScale provides a conversion factor between MKMapPoints and screen points.
When MKZoomScale = 1, 1 screen point = 1 MKMapPoint. When MKZoomScale is
0.5, 1 screen point = 2 MKMapPoints.
Run Code Online (Sandbox Code Playgroud)
所以,我是这样计算的:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
CGSize screenSize = mapView.bounds.size;
MKMapRect mapRect = mapView.visibleMapRect;
MKZoomScale zoomScale = screenSize.width * screenSize.height / (mapRect.size.width * mapRect.size.height);
}
Run Code Online (Sandbox Code Playgroud)
计算结果zoomScale符合定义(我已经检查过)。
我还在方法中的 mapView 上绘制了一个叠加层
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
Run Code Online (Sandbox Code Playgroud)
问题是,我的计算结果zoomScale不等于系统传递给该方法的结果。我希望它们相等,因为drawMapRect:在调整大小后立即调用(实际上,调整大小会导致调用此方法)。
这里有什么问题吗?
我也尝试使用
currentZoomScale = …Run Code Online (Sandbox Code Playgroud) 我有UITableView哪些细胞包含一个UITextField.我UITableViewController是所有这些文本字段的代表.现在,当UITableViewController取消分配时,我想将所有文本字段的委托设置为nil.文本字段有一个标签,所以一旦我有一个单元格,我可以用它的标签来获取它.
问题是如何获得所有创建的细胞?要求UITableView对visibleCells回报率唯一可见的细胞,但它可能发生,有一排是不可见的,咬它仍然有我UIViewController作为代表.所以我真的需要以某种方式获得所有创建的细胞.cellForRowAtIndexPath做同样的事情,所以对我来说也不行.我在这里看到的唯一方法是将所有文本字段存储在数组中,但可能有更好的方法吗?
这是一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"reuseId"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"reuseId"];
UITextField *nameTextField = [[UITextField alloc] initWithFrame:nameTextFieldRect];
nameTextField.tag = TEXT_FIELD_TAG;
nameTextField.delegate = self;
[cell.contentView addSubview:nameTextField];
}
return cell;
}
-(void)dealloc
{
// todo: get all text fields and set theirs delegate to nil
}
Run Code Online (Sandbox Code Playgroud)
好吧,大多数答案都表明我不需要将委托设置为nil,但由于我是偏执狂,我怀疑以下情况是可能的:用户点击"返回"按钮,因此dealloc我view controller …
ios ×9
objective-c ×6
ipad ×4
cocoa-touch ×2
iphone ×2
swift ×2
airplay ×1
autolayout ×1
casting ×1
cocoa ×1
constraints ×1
enums ×1
foundation ×1
macos ×1
mapkit ×1
mkoverlay ×1
uikit ×1
uiscrollview ×1
uitableview ×1
uiview ×1
xcode ×1
xib ×1