小编Shm*_*idt的帖子

如何在Core Data中使用二进制标志?

int32在Core Data数据库中有一个属性.我用它int作为一个enum位字段.

是否可以NSPredicate根据此int的二进制值创建查询项?有点像@"bitFieldAttribute & 0x0001"

我也想知道这是否可以使用二进制类型属性?

iphone core-data nspredicate nsfetchrequest bit-fields

21
推荐指数
3
解决办法
4314
查看次数

Core-Data将保存:方法

我有一个属性modificationDate,我Entity A.想在NSManagedObject保存时设置它的值.但是,如果我尝试在NSManagedObject willSave:方法中这样做,我会收到一个错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to process pending changes before save.  The context is still dirty after 100 attempts.  Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler.' ***
Run Code Online (Sandbox Code Playgroud)

所以,我想知道,设定价值的最佳方法是modificationDate什么?

core-data objective-c nsmanagedobject

21
推荐指数
4
解决办法
1万
查看次数

如何将UITextField子类化并覆盖drawPlaceholderInRect以更改占位符颜色

我有一个UITextField带占位符文本集的3 .其中一个UITextField我希望占位符文本为红色.

现在谷歌搜索后,似乎最好的方法是子类UITextField和覆盖drawPlaceholderInRect.

我如何进行子类化和重写drawPlaceholderInRect?我没有找到任何代码示例或教程,我是Objective-c和iOS开发的新手,所以发现它很难解决.

回答:

创建了一个新的objective-c类,称为CustomUITextFieldPlaceholder子类UITextField.在CustomUITextFieldPlaceholder.m下面的代码中

 @implementation CustomUITextFieldPlaceholder

- (void)drawPlaceholderInRect:(CGRect)rect {
    // Set colour and font size of placeholder text
    [[UIColor redColor] setFill];
    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:12]];
}

@end
Run Code Online (Sandbox Code Playgroud)

在您的项目中实现上述内容

#import "CustomUITextFieldPlaceholder.h"
Run Code Online (Sandbox Code Playgroud)

IBOutlet CustomUITextFieldPlaceHolder *txtName;
Run Code Online (Sandbox Code Playgroud)

注意:这是有效的,我相信是正确的做法,但我还没有完全测试它.希望这个例子在我的情况下帮助其他人.

编辑:

[[UIColor redColor] setFill];
Run Code Online (Sandbox Code Playgroud)

对于

[[UIColor colorWithRed:255.0 green:0.0 blue:0.0 alpha:0.7] setFill];
Run Code Online (Sandbox Code Playgroud)

这样我就可以将不透明度设置为70%来模仿默认占位符.

iphone subclass objective-c uitextfield ios

17
推荐指数
1
解决办法
1万
查看次数

如何从AddressDictionary获取格式化地址NSString?

试图从AddressDictionary获取格式化地址,这是我从CLGeocoder获得的.使用以下代码,没有结果:

subtitle = [NSString stringWithString:[[addressDict objectForKey:@"FormattedAddressLines"]objectAtIndex:0]];
Run Code Online (Sandbox Code Playgroud)

还尝试过:

subtitle = [[[ABAddressBook sharedAddressBook] formattedAddressFromDictionary:placemark.addressDictionary] string];
Run Code Online (Sandbox Code Playgroud)

但是这段代码似乎只适用于Mac OS X.

编译器询问ABAdressBook,但我导入了两个头文件.

#import <AddressBook/ABAddressBook.h>
#import <AddressBook/AddressBook.h>
Run Code Online (Sandbox Code Playgroud)

addressbook ios clgeocoder

15
推荐指数
4
解决办法
3万
查看次数

NSMutableAttributedString添加不同的对齐方式

是否可以在字符串的不同部分添加左对齐和右对齐?

我尝试将对齐属性添加到右侧部分:

    NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
    [paragrahStyle setAlignment:NSTextAlignmentRight];
    [mutableAttributedString addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:rangeOfDate];
Run Code Online (Sandbox Code Playgroud)

但是整个字符串与左边对齐.

objective-c ios6 nsmutableattributedstring

14
推荐指数
2
解决办法
2万
查看次数

将AVAudioPCMBuffer转换为NSData并返回

如何转换AVAudioPCMBufferNSData?如果应该这样做

let data = NSData(bytes: buffer.floatChannelData, length: bufferLength)
Run Code Online (Sandbox Code Playgroud)

那怎么算bufferLength

以及如何转换NSDataAVAudioPCMBuffer

nsdata swift ios8 avaudiopcmbuffer

14
推荐指数
2
解决办法
5879
查看次数

使用UIImage编写UIActivityTypeMessage

如果有人能提供一些见解,那就是徘徊.对于我的生活,我无法弄清楚如何使用UIActivityTypeMessage发送UIImage,尽管有人说这是可能的.

该文件说: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html

UIActivityTypeMessage

该对象将提供的内容发布到消息应用程序.使用此服务时,可以提供NSString和NSAttributedString对象作为活动项的数据.您还可以指定其内容使用sms方案的NSURL对象.适用于iOS 6.0及更高版本.在UIActivity.h中声明.

所以根据我的理解,我只能发送NSString/NSURL.我不认为你有可能.

我正在使用这个:

UIImage *image; // some image here.

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ image ] applicationActivities:nil];
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

objective-c ios6 uiactivity uiactivityviewcontroller

12
推荐指数
1
解决办法
1万
查看次数

NSMutableRLEArray objectAtIndex:effectiveRange ::越界

我尝试将属性分配给3个newClock字符串的最后一个字符,即@"3:33:23".

但是我在构造时遇到错误NSRange:

NSMutableAttributedString *mas = [[NSMutableAttributedString alloc]initWithString:newClock];
[mas addAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]}
 range:NSMakeRange(newClock.length-3,newClock.length)];
Run Code Online (Sandbox Code Playgroud)

objective-c nsrange nsrangeexception ios7

12
推荐指数
1
解决办法
2万
查看次数

命令/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang失败,退出代码为1

错误截图 无法理解如何修复它以及它出现的原因?

    Ld /Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Products/Debug-iphonesimulator/Flylista.app/Flylista normal i386
    cd "/Users/atencion/Documents/Applications Development/Xcode Projects/Flylista"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Products/Debug-iphonesimulator -F/Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Products/Debug-iphonesimulator -filelist /Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Intermediates/Flylista.build/Debug-iphonesimulator/Flylista.build/Objects-normal/i386/Flylista.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework QuartzCore -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Products/Debug-iphonesimulator/Flylista.app/Flylista

ld: duplicate symbol _OBJC_CLASS_$_FlightsViewController in /Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Intermediates/Flylista.build/Debug-iphonesimulator/Flylista.build/Objects-normal/i386/FlightViewController.o and /Users/atencion/Library/Developer/Xcode/DerivedData/Flylista-gcadfttyrgznkmafzaicacwytfey/Build/Intermediates/Flylista.build/Debug-iphonesimulator/Flylista.build/Objects-normal/i386/FlightsViewController.o for architecture i386
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

ios5 xcode4.2

10
推荐指数
1
解决办法
2万
查看次数

如何抑制Master-Detail Controller滑动手势,并在iOS 7上重新创建其行为

默认情况下,UISplitViewController提供滑动手势以纵向模式打开主视图.

不幸的是,即使操作详细页面上的滑块,此手势也会打开主控制器!我在这里发现了另一个问题,这个问题被标记为iOS 5.1报告的错误,但问题仍然存在于iOS7上......

现在有办法在这种情况下抑制这种姿势吗?我意识到我可以通过这样做完全删除它:

splitViewController.presentsWithGesture = NO;
Run Code Online (Sandbox Code Playgroud)

然而,允许手势并仍然有可用的滑块将是很好的!

objective-c uisplitviewcontroller ios7

10
推荐指数
1
解决办法
5244
查看次数