我试图添加一个没有边框的UISearchBar,但它根本不起作用.
这就是我所拥有的:
在XIB文件中,我添加了UISearchBar.风格=黑色透明.Tint =默认.没有选择任何选项(书签,取消按钮,范围栏等).背景=默认.Drawing = opaque(基本上是UISearchBar的默认设置).
我有一个UISearchBar的属性 - searchBar.在实现文件中,当视图加载时,我有:
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)
但无论出于何种原因,背景(盒子周围的黑色边框)根本就没有.我试过[[self.searchBar.subviews objectAtIndex:0] setAlpha:0],但这根本不起作用.
有什么帮助吗?
我试图理解类中getter/setter方法的用法.假设我们有一个名为A的类,其中包含一些公共实例变量,后跟一个带参数的构造函数,其中参数从另一个类(main)传递给它.在构造函数中,我们让那些实例变量等于传递的内容.
现在,如果这个类被另一个程序员使用,没有什么能阻止他们直接访问/更改实例变量到无效的东西.通过将实例变量设为私有,我们可以消除对这些变量的访问.但是,如果我们想要间接地或在某些特定条件下更新/更改这些实例变量,或者只是让该人可以访问实例变量,我们将为此创建一个getter/setter对.
好处?:1.
仅在set()方法下的某些有效原因下
更改实例变量2.因此我们可以显示实例变量实际上是什么而不给使用此类的程序员更改它的能力.
这是正确的解释吗?
#include <iostream>
using namespace std;
class Test {
int a;
public:
int getA() {
return a;
}
Test(): a(1){}
Test(int i): a(i){}
};
int main() {
Test t1(100);
cout << sizeof(t1) << " " << sizeof(1) << endl; // 4 4
return 0;
}
Run Code Online (Sandbox Code Playgroud)
似乎 C++ 中的类根本没有开销。t1 的大小为 4,就像一个整数。如果我向 Test 添加另一个 int 成员,它会将其大小增加到 8。
我会期望大于 4 的东西
课程没有开销是真的吗?
我正在尝试学习如何使用目标C进行开发,并且我在本书中读到,要使用点语法(obj.var)从类中访问ivar,您必须使用@properties实现这些变量,但是我已经尝试过使用它没有为这些变量定义@properties的访问类型,它似乎正常工作.
这种访问如何运作?像Java一样使用它是一个好习惯吗?
例:
ComplexNumber *c1 = [[ComplexNumber alloc]init];
c1.realPart = 3;
c1.imaginaryPart = 2;
Run Code Online (Sandbox Code Playgroud)
ComplexNumber的方法:
- (double)modulus;
-(void)setRadius:(double)aRadius phase:(double)aPhase;
-(void)print;
-(double)realPart;
-(double)imaginaryPart;
-(void)setRealPart:(double)value;
-(void)setImaginaryPart:(double)value;
Run Code Online (Sandbox Code Playgroud) 在iOS 6上,这段代码工作正常:
- (NSString*)cLocalImageName
{
[self willAccessValueForKey:@"cLocalImageName"];
NSString*pathToImage;
if ([self.cIsUserCreated boolValue]) {
pathToImage = [self primitiveValueForKey:@"cLocalImageName"];
}else{
pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@".png"];
}
[self didAccessValueForKey:@"cLocalImageName"];
return pathToImage;
}
Run Code Online (Sandbox Code Playgroud)
即此行始终返回正确的文件路径:
pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@".png"];
Run Code Online (Sandbox Code Playgroud)
但是,在iOS 5上,该行总是返回nil,而我必须调用:
pathToImage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",[self primitiveValueForKey:@"cLocalImageName"]]];
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么这是iOS 5上的问题?
我已经排除的事情:
•[self primitiveValueForKey:@"cLocalImageName"]未返回nil.
•构建应用程序后,.png对象实际上存在于已编译的.app包中.
我正在开发一个使用GCD运行大量后台作业的MacOS X应用程序.后台作业使用CLucene索引文档,并在子上下文中访问Core Data.
这些作业都是在短时间内生成的(在使用DISPATCH_QUEUE_CONCURRENT创建的队列上使用dispatch_async),但只有4个一次完成实际工作.这是使用dispatch_semaphore_t完成的,通过在作业开始时等待它并在作业完成时释放它来完成.
我在以下情况下看到一个非常奇怪,可靠的可重现的死锁:
NSWindow显然陷入僵局,试图在显示菜单栏时发送通知.这是发生这种情况时主线程的堆栈跟踪:
#0 0x00007fff870ae6c2 in semaphore_wait_trap ()
#1 0x00007fff8b1bf486 in _dispatch_semaphore_wait_slow ()
#2 0x00007fff8b69c12b in -[_NSDNXPCConnection sendMessage:waitForAck:] ()
#3 0x00007fff8b57ced5 in _CFXNotificationPost ()
#4 0x00007fff8b58bbf3 in CFNotificationCenterPostNotification ()
#5 0x00007fff902ae174 in HIS_XPC_CFNotificationCenterPostNotification ()
#6 0x00007fff8bd3612a in BroadcastToolboxMessage ()
#7 0x00007fff8bd6d063 in MenuBarInstance::Show(MenuBarAnimationStyle, unsigned char, unsigned char, unsigned char) ()
#8 0x00007fff8bd98144 in SetMenuBarObscured ()
#9 0x00007fff8bd97e0f in HIApplication::HandleActivated(OpaqueEventRef*, unsigned char, OpaqueWindowPtr*) ()
#10 0x00007fff8bd95407 in HIApplication::EventObserver(unsigned int, OpaqueEventRef*, void*) ()
#11 0x00007fff8bd636e0 in _NotifyEventLoopObservers …Run Code Online (Sandbox Code Playgroud) macos cocoa multithreading objective-c grand-central-dispatch
如果我使用以下代码:
- (NSString*)formatToCurrency:(float)inFloat {
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setMaximumFractionDigits:2];
[currencyFormatter setLocale:[NSLocale currentLocale]];
NSNumber *x = [NSNumber numberWithFloat:inFloat];
return [NSString stringWithFormat:@" %@", [currencyFormatter stringFromNumber:x]];
}
Run Code Online (Sandbox Code Playgroud)
然后在调用代码时通过203500,我收到输出:$ 203,500.02.
我很想听听有关正在发生的事情的一些想法.
谢谢,
马特
编辑:当我用调试器查看时,XCode报告了203500,但是当我将浮点数转换为NSString时,它也会显示203500.018.这意味着问题出在浮点数而不是NSNumberFormatter中.
在过去的两天里,我一直在努力解决问题,并且想知道社区是否可以提供帮助.我有一个NSString数字,我需要比较多少个数字匹配另一个字符串中的数字量.
例:
String 1: 14523 25623 651 88
String 2: 9123 88 14523 333
Run Code Online (Sandbox Code Playgroud)
根据这两个字符串,我们可以看到它们都包含"88"和"14523".所以有2场比赛.我不知道如何通过代码找出这种比较.
我想过只需要一个子串来分解字符串1并将每个值与字符串2进行比较,但这是非常低效的.我相信还有更好的方法.
有人可以提供任何建议吗?一个例子将非常感激.谢谢!
我已经能够使用以下C++代码使用OpenGL的glVertexPointer函数:
glVertexPointer(3, GL_DOUBLE, 0, myMeasuredPoints.data());
Run Code Online (Sandbox Code Playgroud)
myMeasuredPoints是一个C++向量,其元素类型为double.使用Visual C++编译此代码时,根本没有问题.但是,当使用MinGW进行编译时,我收到以下错误:
error: 'class std::vector<double, std::allocator<double>' has no member named 'data'
Run Code Online (Sandbox Code Playgroud)
Strangely, I do not get this error any other place in the code where I invoke functions such as myMeasuredPoints.push_back() to push values onto the vector. These other instances have all been before using the .data() function, so it hasn't simply been a case of the code crashing before reaching the other instances.
Any thoughts?
为什么java不会阻止你实例化任何单例类对象?
我试图创建Void类的对象
java.lang.Void
Run Code Online (Sandbox Code Playgroud)
我写了这段代码来创建两个实例
try{
Class clazz = Void.class;
Constructor cons = clazz.getDeclaredConstructor();
cons.setAccessible(true);
Void s2 = (Void) cons.newInstance();
System.out.println(s2);
Void s3 = (Void) cons.newInstance();
System.out.println(s3);
}catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释 - 为什么这在java中是允许的?
objective-c ×6
ios ×5
c++ ×2
java ×2
cocoa ×1
cocoa-touch ×1
iphone ×1
macos ×1
mingw ×1
nsbundle ×1
oop ×1
uisearchbar ×1
variables ×1