我试图理解我在swift中对泛型做错了什么.
我创建了这个示例游乐场
import UIKit
public protocol MainControllerToModelInterface : class {
func addGoal()
init()
}
public protocol MainViewControllerInterface : class {
associatedtype MODELVIEW
var modelView: MODELVIEW? {get set}
init(modelView: MODELVIEW)
}
public class MainViewController<M> : UIViewController, MainViewControllerInterface where M : MainControllerToModelInterface {
public weak var modelView: M?
required public init(modelView: M) {
self.modelView = modelView
super.init(nibName: String(describing: MainViewController.self), bundle: Bundle.main)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
public class Other<C, M> : NSObject where …Run Code Online (Sandbox Code Playgroud) 有人可以帮我关掉Xcode 4中我从子项目获得的警告吗?
我有三个子项目,有很多警告.子项目由我的客户的研发工作室提供.我想关掉那里的警告,把我所有的努力和注意力放在我自己的代码中的警告上.

这可能在Xcode 4中吗?
在我的基于NSPersistenDocument的项目中,我有一个这样的结构
myDocument (NSPersistentDocument) -> myDocument.xib (windows xib)
|
|-> view (the self.view) --> ... "other view"
|
|-> some NSArrayController
|
|-> myResourceViewController --> myResourceViewController.xib
|
|-> view (the self.view)
|
|-> myTreeController (a NSTreeController subclass)
Run Code Online (Sandbox Code Playgroud)
基本上,myResourceViewController是viewController的一个实例,它管理resourceView并管理它们的数据.
在myDocument的awakeFromNib方法中,我有以下代码
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
...
[leftBar addSubview:resourceViewController.view]; //i add resourceViewController's view
resourceViewController.view.frame = leftBar.bounds;
...
}
Run Code Online (Sandbox Code Playgroud)
在myResourceViewController awakeFromNib方法我有:
-(void)awakeFromNib;
{
NSLog(@"%@", [self description]);
[removeButton bind:@"enabled" toObject:resourceTreeController withKeyPath:@"selection" options:[NSDictionary dictionaryWithObject:NSIsNotNilTransformerName forKey:NSValueTransformerNameBindingOption]];
NSArray *draggedTypes = [NSArray arrayWithObjects:ResourceURIPasteBoardType, nil];
[resourceOutlineView registerForDraggedTypes:draggedTypes];
}
Run Code Online (Sandbox Code Playgroud)
NSLog说,myResourceViewController的同一个实例的awakeFromNib被称为4次,我不明白为什么.我唯一的ResourceViewController是在myDocument xib中创建的.我到处都不使用NSNib加载方法.
我正在开发一个iOS5 +项目(xcode 4.4.1 SDK 5.1)
我在单元测试中有这个代码:
[_appDelegate application:nil didFinishLaunchingWithOptions:nil];
UITabBarController *tabBarController = (UITabBarController*)_appDelegate.window.rootViewController;
NSArray *viewControllers = [tabBarController viewControllers];
UINavigationController *nc_1 = [viewControllers objectAtIndex:0];
UIViewController *vc_1 = nc_1.topViewController;
STAssertTrue([vc_1 isKindOfClass:[ScheduleViewController class]]==YES, @"UITabBarController first tab should be a ScheduleViewController class");
Run Code Online (Sandbox Code Playgroud)
如果我运行测试,测试失败.
所以我检查调试器:
(lldb) po [ScheduleViewController class]
(id) $1 = 0x00142b04 ScheduleViewController
(lldb) po vc_1
(UIViewController *) $2 = 0x11a32dc0 <ScheduleViewController: 0x11a32dc0>
(lldb) print (BOOL) [vc_1 isKindOfClass:(Class)[ScheduleViewController class]]
(BOOL) $4 = YES
(lldb) po [vc_1 class]
(id) $5 = 0x00142b04 ScheduleViewController
(lldb)
Run Code Online (Sandbox Code Playgroud)
在应用程序中:didFinishLaunchingWithOptions:我创建一个ScheduleViewController,我将它用作导航控制器的rootController.调试器说它是正确的.我不明白上面的断言有什么问题. …
我有一个应用程序,我正在创建一个视图层次结构,我有一个mapview和一个tableview.mapview位于tableview下,当表垂直偏移为负时,它在顶部可见.视图的结构是这样的:
黄色是地图的地方,顶部的绿色是导航栏,底部的绿色是桌面视图.
滚动表格视图时,地图应显示地图可见部分中心的用户位置.
我遇到的问题是,当我应用视差时,地图中心不是我正在设置的位置.这是我用来隔离问题的示例项目的屏幕截图.中心坐标是白金汉宫.
橙色方块是一个调试视图,位于mapView的中心(中心坐标应该是).我确信视差效果是正确的.
关于示例项目中mapView的视图层次结构如下图所示.视图的位置反映了上面的截图.
以下代码用于设置mapContainerView的frame.origin.y值.我正在使用mapContainerView来避免触摸mapView的帧来执行视差效果.mapView是mapContainerView的子视图(在开始时我在mapView上使用了一个翻译,但是我改变了代码以试图找出这个问题的原因)
self.mapViewContainer.frame = CGRectMake(0, self.currentY, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
if (!CGRectEqualToRect(self.mapViewContainer.bounds, self.mapView.bounds)) {
self.mapView.bounds = CGRectMake(0,
0,
CGRectGetWidth(self.mapViewContainer.bounds),
CGRectGetHeight(self.mapViewContainer.bounds));
self.mapView.center = CGPointMake(CGRectGetMidX(self.mapViewContainer.bounds),
CGRectGetMidY(self.mapViewContainer.bounds));
}
self.squareView.bounds = CGRectMake(0, 0, 22.0f, 22.0f);
self.squareView.center = CGPointMake(CGRectGetMidX(self.mapViewContainer.bounds),
CGRectGetMidY(self.mapViewContainer.bounds));
Run Code Online (Sandbox Code Playgroud)
我的猜测是状态栏正在对mapView做些什么.如果您查看模拟器截图,您可以注意到中心坐标是如何精确定位在从状态栏到mapView底部的垂直空间的中心.
如果我在viewDidLoad中设置坐标的中心,则在创建地图后(当它的帧是CGRectZero时),地图的中心正确地位于地图的中心.
如果我稍后更改它(例如使用计时器,为了模拟位置更新,设置与viewDidLoad中设置的相同的地图区域),地图视图决定更改中心,如上所示.
我找不到任何方法来禁用或更改此行为.我在这里做错了吗?我正在努力解决方法,但我很想知道是否有人知道我在这里缺少什么.
这是我创建的示例项目的代码,用于在隔离场景中重现问题.https://gist.github.com/lucabartoletti/a5f103cb74a3edb178d6
我有一些限制.
我该如何本地化密钥UIApplicationShortcutItemTitle?
我知道本地化是如何工作的像钥匙NSLocationUsageDescription和NSLocationAlwaysUsageDescription:你把你定位在InfoPlist.strings文件.
但是,这些是文档路径中的唯一键.
在这种情况下,我将为UIApplicationShortcutItemTitle每个快速操作设置一个,嵌套在字典和数组中.
如何本地化这些嵌套值?
我需要在我的iPhone应用程序中使用多语言coredata数据库.我可以为每种语言创建不同的数据库但我希望在iphone sdk中存在一种自动方式来管理不同语言核心数据中的数据,例如资源和字符串.
有人有一些提示吗?
当我使用Xcode 12.5和Swift 5.4运行我的应用程序时。我在 pre-main 中崩溃了:
instantiating class metadata for class with missing weak-linked ancestor
相同的代码在Xcode 12.4和Swift 5.3上运行没有问题
我的问题与
UIView/CALayer:转换在superview中触发layoutSubviews
据报道,来自苹果的TSI回复:
通常,更改视图(或图层)的几何属性将触发视图层次结构上的级联布局失效,因为父视图可能具有涉及已修改子项的自动布局约束.请注意,无论您是否已明确启用自动布局,它都会以某种形式激活.
在我的情况下,我有一个非常简单的视图层次结构,其中视图A包含视图B.
在A的布局子视图中设置B的帧.
当我在B的背衬层上执行动画(变换和不透明)时,有时会调用A的layoutSubviews.这显然是一个问题,因为我在A的layoutSubviews中设置了B的框架,这打破了动画.
如何避免B的布局和动画之间的这种冲突?
有一种方法可以自定义通过performBatchUpdates完成的动画的时间安排吗?
我有这个代码
[self.stepCollectionView performBatchUpdates:^{
self.stepSelectedIndex = indexPath.row;
UICollectionViewCell *cell = [self.stepCollectionView cellForItemAtIndexPath:indexPath];
[UIView transitionWithView:cell
duration:0.5f
options: UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionBeginFromCurrentState
animations:^{
CGRect frame = cell.frame;
frame.size.height = 416;
cell.frame = frame;
}
completion:^(BOOL finished) {
}];
} completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)
我将更改UICollectionViewCell的高度,同时重新组织UICollectionViewCell的子视图.