我试图在我的项目中的一个文件中定义常量.
我知道,我可以像下面这样定义它
const CGSize kSize = { 46.f, 44.f };
Run Code Online (Sandbox Code Playgroud)
但我想要实现这样的目标:
if device type iPad
const CGSize kSize = { 146.f, 144.f };
else
const CGSize kSize = { 46.f, 44.f };
Run Code Online (Sandbox Code Playgroud)
是否有可能实现上述目标?
任何人都可以帮助我如何实现这一目标.任何帮助或任何指导都会有所帮助.
我定义了一个像这样的新类:
@interface SomeClass : NSObject {
int wide;
}
- (id)initWithWide:(int)value;
@end
Run Code Online (Sandbox Code Playgroud)
当我实现它时,initWithWide方法如下:
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide = value;
}
@end
Run Code Online (Sandbox Code Playgroud)
Xcode向我显示错误:"Expected identifier or'('".当我将"宽"变量名改为else时,没关系.所以看起来我不能在Objective-C中使用"wide"作为变量名?
@interface SomeClass : NSObject {
int wide1;
}
- (id)initWithWide:(int)value;
@end
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide1 = value;
}
@end
Run Code Online (Sandbox Code Playgroud) 我正在尝试从自己的nib文件创建一个NSWindow,但它似乎比我预期的更难...
NSWindowController提供了init(windowNibName: String?)一种可以被子类覆盖的方法.似乎不可能在init(windowNibName: String?)不覆盖它的情况下调用基类(编译器显示错误消息,即没有采用该String参数的初始化程序).
但是当重写此init(...)方法时,您必须遵循初始化链,这会强制您调用指定的初始化程序.这个指定的初始化程序是init(window: NSWindow!).
这就是我现在被困住的地方......似乎我必须创建一个NSWindow对象(不知何故)才能将它传递给指定的初始化程序.但我不知道如何从nib文件创建NSWindow.
有人有任何线索吗?
我无法确定当前滚动是否设置为反向模式,我想显示该设置并将其用于滑块和其他内容。
我知道我可以检查一下 plist:
dict = open("/Library/Preferences/.GlobalPreferences.plist");
=> dict.objectForKey("com.apple.swipescrolldirection");
Run Code Online (Sandbox Code Playgroud)
我正在寻找任何API在这里。
我们在某些线程中使用coredata ...(太多的并发上下文都很糟糕 - 我知道,我经历过它)
现在围绕每个获取/保存coredata包装锁.
我现在想测量一个线程等待获取锁定所花费的时间.
我以为我可以使用时间分析器甚至是线程状态仪器或采样器.但是: - 时间分析器只是忽略等待(可能是因为它不是CPU调用) - 采样器(即使他不是cpu模式) - 线程状态仪器也没有显示我正确的callstack :( [但也许(并且这总是一个)可能)我忽略了一个简单的解决方案]
在这里我有一个非常简单的应用程序,也有一个锁,我也没有得到等待时间...也许你可以帮助我得到主线程在这个例子中等待的时间 - 使用一些分析技术我可以然后转移到coredata案例:
@implementation DDAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLock *l = [[NSLock alloc] init];
NSLog(@"made");
[NSThread detachNewThreadSelector:@selector(hogTheLog:) toTarget:self withObject:l];
NSLog(@"wait");
[l lock];
NSLog(@"got");
[l unlock];
NSLog(@"terminate");
[NSApp terminate:nil];
}
- (void)hogTheLog:(NSLock*)l {
[l lock];
sleep(3);
[l unlock];
}
@end
Run Code Online (Sandbox Code Playgroud) 那么,如何拥有一个具有简单内容且具有枚举值限制的 XSD 复杂类型呢?
(!) 没有额外的简单类型:
所以...有点像这样: -- 仅工作;) (请注意,这是一个简化的示例。请参阅我喜欢实现的 xml)
<element name="question">
<complexType>
<simpleContent>
<enumeration value="no"></enumeration>
<enumeration value="maybe"></enumeration>
<enumeration value="yes"></enumeration>
<xs:attribute name="name" type="xs:string" />
</extension>
</simpleContent>
</complexType>
</element>
Run Code Online (Sandbox Code Playgroud)
--
最后,这是我的 xml 的模拟:
<question name="foo">
yes
</question>
Run Code Online (Sandbox Code Playgroud)
这是我的课:
class Some: UIView{
override init(frame: CGRect) {
super.init(frame: frame)
load()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
load()
}
private func load(){
let someImage = UIImageView()
someImage.translatesAutoresizingMaskIntoConstraints = false
someImage.image = UIImage(named: "Test")
self.addSubview(someImage)
someImage.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
someImage.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
someImage.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.5)
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
(橙色是我的ViewController的背景)
为什么我的图像会忽略以下行:
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
someImage.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5)
Run Code Online (Sandbox Code Playgroud)
在图像中,它的倍数显然为1.0。实际上,它应该占据屏幕一半的高度和宽度,如乘数(0.5)所示。我究竟做错了什么?
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSMutableArray *finalArray = [(NSArray*)filePathsArray mutableCopy];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *files = [fm contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSString *fileFirst = [files objectAtIndex:0];
NSString *fullPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileFirst];
/* NSUInteger index = [finalArray indexOfObject:@".DS_Store"];
[finalArray removeObjectAtIndex: index]; */
//NSLog(@"files array %@", finalArray);
NSString …Run Code Online (Sandbox Code Playgroud) 在Apple的iOS Devs论坛上发帖后没有回答,我试图看看是否有人对这样的问题有任何经验.我正在使用xcode for iOS 7.
MapView不会更新.我很确定模拟器中的问题,但我不知道如何检查它.我喜欢把这个项目放在一个真实的设备上,但我的iOS 7设备还在商店里.
我创建了嵌套在View下的MKMapView(嵌套在ViewController下) - >将CoreLocation和MapKit添加到Frameworks中 - >将MKMapView连接到右侧属性mapView.
我的文件看起来像这样:
MapScanViewController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapScanViewController : UIViewController<MKMapViewDelegate>
// I was trying to create a label and print the
// userLocation description into the label - but none worked
@property (nonatomic,retain) IBOutlet UILabel *myLabel;
@property (nonatomic,strong) IBOutlet MKMapView *mapView;
@end
Run Code Online (Sandbox Code Playgroud)
和MapScanViewController.m:
#import "MapScanViewController.h"
@implementation MapScanViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.delegate = self;
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, …Run Code Online (Sandbox Code Playgroud) 我想在Mac上的Excel 2011的一些Visual Basic宏中使用Try ... Catch块而不是On Error.但是,它似乎没有认识到这些术语.这种处理异常的方法在Mac上不可用吗?
我想修改弹出板在来电视图上显示的标签(例如添加城市信息).我的应用程序不需要上传到AppStore,但必须在没有越狱的设备上工作.谢谢.
objective-c ×7
ios ×6
cocoa ×2
swift ×2
xcode ×2
autolayout ×1
cocoa-touch ×1
const ×1
core-data ×1
enums ×1
instruments ×1
iphone ×1
macos ×1
mapkit ×1
mkmapview ×1
uiimage ×1
uiimageview ×1
xml ×1
xsd ×1