使用SDK 6.1,Xcode 4.6.1,我制作了一个新项目Master-Detail iOS App,ARC,没有故事板.
然后在DetailViewController,在viewDidLoad我添加UITableViews中包含的两个s,UIViewController并确保第二个隐藏如下:
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *lViewController1 = [[UIViewController alloc] init];
UITableView *lTableView1 = [[UITableView alloc] initWithFrame: self.view.frame];
lTableView1.scrollsToTop = YES;
[lViewController1.view addSubview: lTableView1];
lTableView1.dataSource = self;
[self.view addSubview: lViewController1.view];
[self addChildViewController: lViewController1];
UIViewController *lViewController2 = [[UIViewController alloc] init];
UITableView *lTableView2 = [[UITableView alloc] initWithFrame: self.view.frame];
lTableView2.scrollsToTop = YES;
[lViewController2.view addSubview: lTableView2];
lTableView2.dataSource = self;
[self.view addSubview: lViewController2.view];
[self addChildViewController: lViewController2];
// now hide the view …Run Code Online (Sandbox Code Playgroud) 使用UITextView时,我尝试将自定义属性添加到属性字符串.但是,在分配到UITextView的attributedText后,所有自定义键都将丢失.像这样:
NSMutableAttributedString *lString = [[ NSMutableAttributedString alloc ] initWithString: @"astring"
attributes: @{ @"customkey": @"customvalue" }];
NSLog(@"string: %@", lString); // shows customkey present
textView.attributedText = lString;
NSLog(@"result: %@", self.textView.attributedText); // shows customkey missing
Run Code Online (Sandbox Code Playgroud)
这应该有用吗?
在我的模型中,我设置了一个Entity(让我们说Person)将一个属性作为字符串(称为"name"),然后在其上放置一个索引.如果我对我的模型进行了大量查询,那么查询就会导致性能下降.我的查询很简单
[ NSPredicate predicateWithFormat: @"%K == %@", @"name", lPersonName ];
Run Code Online (Sandbox Code Playgroud)
所以我认为索引会完成它的工作.
然后,如果我计算一些简单的哈希标记并将其与我的实体一起存储在索引的整数属性(称为"哈希")中,并执行更窄的查询,则性能消耗就会消失.像这样:
[ NSPredicate predicateWithFormat: @"%K == %d AND (%K == %@)",
@"hash", [ self calculateHashForName: lPersonName ],
@"name", lPersonName ];
Run Code Online (Sandbox Code Playgroud)
为什么整数上的索引比字符串上的索引快得多?我忽略了什么吗?这是核心数据问题吗?
当然,我可以使用哈希标记保留解决方案,但如果我忽略了一些我很想知道的事情,而不是迟早.
在iOS上,应用程序可以使用不同的语言系统语言如果开发商传递NSLocale给适合的情况下,或者如果适当的值写入NSUserDefault的AppleLanguages关键.
我似乎也没有找到一种方法来处理该区域,这是一个负责数字格式化的部分.
这里使用的情况是,我要UITextfield的DecimalPad键盘无论显示小数逗号什么系统的区域设置为.
这可能吗?
在创建半透明窗口(基于Matt Gemmell的示例代码)之后,我想在此窗口中获取键盘事件.当我的应用程序是活动应用程序时,似乎只有键盘事件,而我想要键盘事件,即使我的应用程序不活动但窗口可见.
基本上我想要Quicksilver应用程序(blacktree)提供的行为.
有没有人对如何做到这一点有任何暗示?
我想,这个想法是这样的:无论 SwiftUI 中尚未提供什么,都可以使用 UIViewRepresentable 来解决。所以我开始为 TTTAttributedLabel 制作一个 UIViewRepresentable。
但是 API 中缺少一些基本的东西,或者我缺少一些基本的东西:如何设置 UIViewRepresentable 的“内在内容大小”?
就像 SwiftUI 一样Text,我希望我的组件能够根据其容器的大小将自身设置为特定大小。
我的第一个想法是使用内在内容大小,所以我创建了这个:
class SizeRepresentableView: UILabel {
override init(frame: CGRect) {
super.init(frame: CGRect.zero)
text="hello"
backgroundColor = UIColor.systemYellow
}
override var intrinsicContentSize: CGSize {
return CGSize(width: 100, height: 100)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
struct SizeRepresentable: UIViewRepresentable {
func updateUIView(_ uiView: SizeRepresentableView, context: Context) {
}
typealias UIViewType = SizeRepresentableView
func makeUIView(context: UIViewRepresentableContext<SizeRepresentable>) -> SizeRepresentableView {
let v …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个类似于滑块的自定义 UIControl。
该控件是一个视图的子视图,该视图还附加了一个点击手势识别器。
现在的问题是这个点击手势识别器取消了发送到我的控件的触摸。有没有办法可以从我的控件代码中覆盖它?
如果我查看 iOS 中的标准控件,它看起来好像 UIButton 有一种覆盖点击手势识别器的方法,但 UISlider 没有。所以如果我用 UIButton 替换我的自定义控件,点击手势识别器不会触发它的动作,但如果我用滑块替换它,它会触发。
编辑:我在 Xcode 中做了一个小项目来玩。在此处下载https://dl.dropboxusercontent.com/u/165243/TouchConcept.zip并尝试更改它以便
编码:
// inherit from UIButton will give the wanted behavior, inherit from UIView (or UIControl) gives
// touchesCancelled by the gesture recognizer
@interface UICustomControl : UIView
@end
@implementation UICustomControl
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ NSLog(@"touchesBegan"); }
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{ NSLog(@"touchesMoved"); }
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ NSLog(@"touchesEnded"); } …Run Code Online (Sandbox Code Playgroud) ios ×6
cocoa-touch ×2
cocoa ×1
core-data ×1
iphone ×1
macos ×1
nspredicate ×1
objective-c ×1
performance ×1
swift ×1
swiftui ×1
uikit ×1
uitextview ×1