小编Shm*_*idt的帖子

如何从货币代码获取NSLocale?

我在尝试这个:

NSDictionary *components = [NSDictionary dictionaryWithObject:@"USD" forKey:NSLocaleCurrencyCode];
NSString *localeIdentifier = [NSLocale localeIdentifierFromComponents:components];
NSLocale *localeForDefaultCurrency = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];
Run Code Online (Sandbox Code Playgroud)

它创建NSLocale对象,但它不包含任何区域信息.例如,

[localeForDefaultCurrency objectForKey:NSLocaleCountryCode];
Run Code Online (Sandbox Code Playgroud)

返回零;

知道如何从货币代码中获取NSLocale吗?

currency objective-c nslocale

7
推荐指数
3
解决办法
4513
查看次数

错误: - [UIImage _deleteExternalReferenceFromPermanentLocation]无法识别的选择器发送到实例

当我删除包含图像的托管对象时,在外部记录中存储为可转换的值,然后我崩溃并出现此错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _deleteExternalReferenceFromPermanentLocation]: unrecognized selector sent to instance 0xde49360' 
Run Code Online (Sandbox Code Playgroud)

core-data transformable ios5

7
推荐指数
1
解决办法
1875
查看次数

取消本地通知无效

我花了一半的时间阅读所有"如何取消本地通知"的问题和答案.毕竟,我提出了自己的解决方案,但显然它无法正常工作.我有一个包含所有预定通知的tableview ....

在我的H文件上

@property (strong, nonatomic) UILocalNotification *theNotification;
Run Code Online (Sandbox Code Playgroud)

然后在M文件上:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    theNotification = [notificationArray objectAtIndex:indexPath.row];
    NSLog(@"Notification to cancel: %@", [theNotification description]); 
    // NSLOG Perfectly describes the notification to be cancelled. But then It will give me      "unrecognized selector"


    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Local Reminder"
                                                    message:@"Cancel local reminder ?"
                                                   delegate:self
                                          cancelButtonTitle:@"No"
                                          otherButtonTitles:@"Yes", nil];
    [alertView show];
    [alertView release];    
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) { …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview xcode4 uilocalnotification ios5

7
推荐指数
1
解决办法
4370
查看次数

NSPredicate NSManagedObject的NSNumber属性

我有NSNumber * year属性NSManagedObject,它的数据模型类型是Integer 16.

我试着查看NSPredicate今年,但找不到合适的一个.

我尝试了什么:

NSPredicate *p = nil;
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
NSNumber *yearNo = [nf numberFromString:term];
if (yearNo) {
    p = [NSPredicate predicateWithFormat:@"(cars.year == %i)", yearNo.intValue];
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

NSPredicate *p = nil;
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
NSNumber *yearNo = [nf numberFromString:term];
if (yearNo) {
    p = [NSPredicate predicateWithFormat:@"(cars.year == %@)", yearNo];
}
Run Code Online (Sandbox Code Playgroud)

在这两种情况下应用程序崩溃.

core-data objective-c nspredicate ios6

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

尝试设置滑动以删除单元格,当我们已经有一个....这似乎不好

Cell不允许删除它.滑动发生时,它会向后滑动,因此无法将其删除.控制台中的消息说:

attempting to set a swipe to delete cell when we already have one....
that doesn't seem good
Run Code Online (Sandbox Code Playgroud)

码:

#import "GroupDetailInfoViewController.h"
#import "YFJLeftSwipeDeleteTableView.h"

@interface GroupDetailInfoViewController ()

{
    NSMutableArray * _dataArray;
    UIButton * _deleteButton;
    NSIndexPath * _editingIndexPath;

    UISwipeGestureRecognizer * _leftGestureRecognizer;
    UISwipeGestureRecognizer * _rightGestureRecognizer;
    UITapGestureRecognizer * _tapGestureRecognizer;
}

@property (nonatomic, retain) YFJLeftSwipeDeleteTableView *tableView;
@end


@implementation GroupDetailInfoViewController

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initialization
        _dataArray = [@[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)] mutableCopy]; …
Run Code Online (Sandbox Code Playgroud)

uitableview ios ios7

7
推荐指数
1
解决办法
2165
查看次数

如何用AVAudioPCMBuffer播放声音

我无法用AVAudioPCMBuffer播放声音(尽管我可以使用AVAudioFile).我收到了这个错误.

错误:AVAudioBuffer.mm:169: - [AVAudioPCMBuffer initWithPCMFormat:frameCapacity:]:必需条件为false:isCommonFormat

这是我下面的代码,我非常感谢你的帮助.

import UIKit
import AVFoundation

class ViewController: UIViewController {

let audioEngine: AVAudioEngine = AVAudioEngine()
let audioFilePlayer: AVAudioPlayerNode = AVAudioPlayerNode()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    audioEngine.attachNode(audioFilePlayer)

    let filePath: String = NSBundle.mainBundle().pathForResource("test", ofType: "mp3")!
    let fileURL: NSURL = NSURL(fileURLWithPath: filePath)!
    let audioFile = AVAudioFile(forReading: fileURL, error: nil)
    let audioFormat = audioFile.fileFormat
    let audioFrameCount = UInt32(audioFile.length)
    let audioFileBuffer = AVAudioPCMBuffer(PCMFormat: audioFormat, frameCapacity: audioFrameCount)

    var mainMixer …
Run Code Online (Sandbox Code Playgroud)

swift ios8 avaudiopcmbuffer avaudiofile avaudioplayernode

7
推荐指数
1
解决办法
5975
查看次数

RTF文件到属性字符串

我试图读取RTF文件内容属性串,不过attributedTextnil.为什么?

if let fileURL = NSBundle.mainBundle().URLForResource(filename, withExtension: "rtf") {
    var error: NSError?
    if let attributedText = NSAttributedString(fileURL: fileURL, options: [NSDocumentTypeDocumentAttribute:NSRTFDTextDocumentType], documentAttributes: nil, error: &error){
        textView.attributedText = attributedText
    }
}
Run Code Online (Sandbox Code Playgroud)

更新.:我将代码更改为:

if let fileURL = NSBundle.mainBundle().URLForResource(filename, withExtension: "rtf") {
    var error: NSError?

    let attributedText = NSAttributedString(fileURL: fileURL, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil, error: &error)
        println(error?.localizedDescription)


        textView.attributedText = attributedText

}
Run Code Online (Sandbox Code Playgroud)

现在崩溃textView.attributedText = attributedText说:fatal error: unexpectedly found nil while unwrapping an Optional value.我在调试器中看到attributedText非零,并包含带有文件属性的文本.

nsattributedstring ios7.1 swift

7
推荐指数
1
解决办法
3731
查看次数

使用NSFetchedResultsController时是否可以获得明显的结果?

我有一个产品搜索,搜索我的产品所在的ProductCategories,有时我的产品有多个类别,这给我重复的结果.我不想直接搜索产品表,因为有几种产品有多种尺寸,但基本上是相同的产品.

有没有办法用NSFetchedResultsController获得不同的搜索结果?

iphone core-data objective-c nsfetchedresultscontroller

6
推荐指数
2
解决办法
2702
查看次数

UITableViewCell imageView没有显示

所以我有以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"FriendsCell";

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row];

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    [cell.imageView  setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)];
    [cell.textLabel setText:fd.name_];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

但是,我没有在单元格中看到imageView.我究竟做错了什么?

iphone objective-c ipad ios afnetworking

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

UITableView reloadRowsAtIndexPaths隐藏行

我使用UITableView和静态单元格.如果我使用reloadData,比一切都好.

如果我尝试reloadRowsAtIndexPaths它隐藏行.如果我向上拖动tableView(当单元格更新时),则会出现行.

uitableview ios5

6
推荐指数
2
解决办法
2145
查看次数