我正在开发一个iPhone应用程序,它可以作为打开和关闭灯泡的遥控器,我正在使用UIButtons来做到这一点:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button setBackgroundImage:bulb_on forState:UIControlStateSelected];
[button setBackgroundImage:bulb_off forState:UIControlStateNormal];
button.frame = CGRectMake(SPACING_LEFT + (BUTTON_SPACING * buttonNum) % (NUMBER_OF_HORIZONTAL_BUTTONS * BUTTON_SPACING), SPACING_TOP + y_padding, BUTTON_SIZE_X, BUTTON_SIZE_Y);
[self.scrollView addSubview:button];
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了一点点,但仍然令人烦恼的细节:

如您所见,所选按钮的左上角有一些蓝色的"框"或阴影.正常状态下的按钮没有这样的东西.它可以来自什么,以及如何删除它?
我有一个我想用XCTest测试的类,这个类看起来像这样:
public class MyClass: NSObject {
func method() {
// Do something...
// ...
SingletonClass.sharedInstance.callMethod()
}
}
Run Code Online (Sandbox Code Playgroud)
该类使用以下形式实现的单例:
public class SingletonClass: NSObject {
// Only accessible using singleton
static let sharedInstance = SingletonClass()
private override init() {
super.init()
}
func callMethod() {
// Do something crazy that shouldn't run under tests
}
}
Run Code Online (Sandbox Code Playgroud)
现在进行测试.我想测试method()实际上它应该做什么,但我不想调用代码callMethod()(因为它做了一些可怕的异步/网络/线程的东西,不应该在MyClass的测试下运行,并将使测试崩溃).
所以我基本上想做的是:
SingletonClass = MockSingletonClass: SingletonClass {
override func callMethod() {
// Do nothing
}
let myObject = MyClass()
myObject.method()
// Check if …Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的C项目中为嵌入式设备调用Rust代码.设备通过UART打印,因此我可以看到我的通话结果是什么.
下面的C和Rust代码按预期工作(我省略了许多使其编译所需的样板代码).
C:
uint8_t input[] = {1,2,3};
uint8_t output[] = {4,5,6};
output = func(input, output);
printf("Sum: %d", output[0]);
Run Code Online (Sandbox Code Playgroud)
锈:
#[no_mangle]
pub extern fn func(input: &[u8], dst: &mut[u8]) -> u8 {
3
}
Run Code Online (Sandbox Code Playgroud)
这按预期打印3.但我坚持改变作为参考传入的数组:
C:
uint8_t input[] = {1,2,3};
uint8_t output[] = {4,5,6};
func(input, output);
printf("Sum: %d", output[0]);
Run Code Online (Sandbox Code Playgroud)
锈:
#[no_mangle]
pub extern fn func(input: &[u8], dst: &mut[u8]) {
for i in (0..1) {
dst[i] = input[i];
}
}
Run Code Online (Sandbox Code Playgroud)
这编译,但打印4而不是预期1.由于某种原因,我无法更改数组的值.有任何想法吗?
编辑:C函数声明分别是:
extern uint8_t func(uint8_t in[64], uint8_t output[64]);
extern void func(uint8_t in[64], uint8_t …Run Code Online (Sandbox Code Playgroud) 我正在一个在嵌入式设备上使用Rust的项目上进行工作,在这里我试图在Rust中编写可以从C调用的函数。我在没有标准库的情况下编译了该项目,或多或少地遵循了本教程:Embedded Rust Right现在!
我的Rust代码可以很好地编译为.o文件,但是在尝试使用arm-none-eabi-ld将C和Rust对象文件链接在一起时遇到了麻烦。我收到类似以下错误:
rustfunc.o: In function `func':
rustfunc.0.rs:(.text.hash+0x18): undefined reference to `__aeabi_memclr8'
...
/rust/src/libcore/slice.rs:1446: undefined reference to `__aeabi_memcpy'
/rust/src/libcore/fmt/num.rs:196: undefined reference to `__aeabi_memclr4'
Run Code Online (Sandbox Code Playgroud)
最让我困惑的是,即使我只是将目标文件链接在一起,但这些错误同时引用了我的Rust代码和libcore中的代码。
是否有人知道这些错误是什么意思,以及链接器为何无法解决这些问题?谢谢!
我正在使用S7Graphview编写一个iPhone应用程序,我将一些日期和结果保存为.plist作为字典中的键和值,两者都作为字符串.我的plist看起来像这样:
<dict>
<key>2011-05-11</key>
<string>23</string>
<key>2011-05-12</key>
<string>23</string>
<key>2011-05-13</key>
<string>23</string>
<key>2011-05-14</key>
<string>43</string>
<key>2011-06-14</key>
<string>43</string>
</dict>
Run Code Online (Sandbox Code Playgroud)
然后我使用这个循环将这些值加载到graphview中:
NSMutableDictionary* dictionary = [[NSMutableDictionary alloc]init];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
int i = 1;
if ([dictionary count] > 0) {
for (NSString* key in dictionary){
NSString* verdiString = [dictionary objectForKey:key];
CGFloat verdi = [verdiString intValue];
NSDate *dato = [[NSDate alloc]init];
NSLog(@"key=%@ value=%@", key, [dictionary objectForKey:key]);
dato = [self stringTilDato:key];
[items.list_ addObject:[[GraphInfo alloc] initWithID:i name:verdiString value:verdi date:dato]];
i++;
}
}
Run Code Online (Sandbox Code Playgroud)
"stringTilDato"方法将日期字符串转换为NSDate.值被加载到items.list中,但顺序错误!NSLog报告:
key=2011-05-14 value=43
key=2011-05-13 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将UIImagePickerController中的相机闪光模式设置为关闭,但我不明白参考页面.这是我的代码:
- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType {
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
if ([UIImagePickerController isSourceTypeAvailable:
sourceType] && [mediaTypes count] > 0) {
NSArray *mediaTypes = [UIImagePickerController
availableMediaTypesForSourceType:sourceType];
mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
UIImagePickerControllerCameraDevice *device;
picker.mediaTypes = mediaTypes;
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
[picker release];
}}
Run Code Online (Sandbox Code Playgroud)
我已经尝试设置picker.cameraDevice = UIImagePickerControllerCameraFlashModeOff,但这会导致错误.参考页面说cameraDevice是一个属性.这是否意味着我需要自己创建该属性,还是位于某处?'如果我对代码没有任何操作,但闪光模式设置为自动,则相机正常工作...
显然有一些我不理解的东西.:/