我在尝试这个:
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吗?
当我删除包含图像的托管对象时,在外部记录中存储为可转换的值,然后我崩溃并出现此错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _deleteExternalReferenceFromPermanentLocation]: unrecognized selector sent to instance 0xde49360'
Run Code Online (Sandbox Code Playgroud) 我花了一半的时间阅读所有"如何取消本地通知"的问题和答案.毕竟,我提出了自己的解决方案,但显然它无法正常工作.我有一个包含所有预定通知的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) 我有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)
在这两种情况下应用程序崩溃.
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) 我无法用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) 我试图读取RTF文件内容属性串,不过attributedText是nil.为什么?
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非零,并包含带有文件属性的文本.
我有一个产品搜索,搜索我的产品所在的ProductCategories,有时我的产品有多个类别,这给我重复的结果.我不想直接搜索产品表,因为有几种产品有多种尺寸,但基本上是相同的产品.
有没有办法用NSFetchedResultsController获得不同的搜索结果?
所以我有以下代码:
- (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.我究竟做错了什么?
我使用UITableView和静态单元格.如果我使用reloadData,比一切都好.
如果我尝试reloadRowsAtIndexPaths它隐藏行.如果我向上拖动tableView(当单元格更新时),则会出现行.
objective-c ×5
core-data ×3
ios5 ×3
uitableview ×3
ios ×2
iphone ×2
swift ×2
afnetworking ×1
avaudiofile ×1
currency ×1
ios6 ×1
ios7 ×1
ios7.1 ×1
ios8 ×1
ipad ×1
nslocale ×1
nspredicate ×1
xcode4 ×1