Tag: 客观的

单例实例与类方法

在最近使用Objective-C和其中编写的各种库时,我注意到了两个非常stream行的单例模式。 一个版本获取单例实例并调用其实例方法,而其他版本只暴露类方法,从不给你一个实例。 所有这些都具有抽象访问单个资源(StoreKit,CoreData,Parse API等)的目的。 例如,以下是MKStoreKit中使用的前一种方法: // initialize singleton during app boot [MKStoreManager sharedManager] // sometime later in the app [[MKStoreManager sharedManager] buyFeature:kFeatureAId onComplete:^(NSString* purchasedFeature) { NSLog(@"Purchased: %@", purchasedFeature); } onCancelled:^ { NSLog(@"User Cancelled Transaction"); }]; 或者NSUserDefaults,UIApplication等等。另一种方法可以在MagicalRecord或者Parse API中看到: // configure API credentials sometime during app boot [Parse setApplicationId:@"123456" clientKey:@"123456"]; // sometime later PFObject *testObject = [PFObject […]

为什么UICollectionView的UICollectionViewCell在用户触摸上不突出显示?

我有一个由自定义的UICollectionViewCell子类组成的UICollectionView。 单元格显示正确,并通过触发此方法正确响应用户的触摸: – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 不过,我的理解是,当用户触摸单元格时,应该突出显示(蓝色),然后当用户抬起手指时突出显示应该消失。 这没有发生。 任何想法为什么? 这里是一些相关的代码: 在UICollectionView的数据源中: @implementation SplitCheckViewCollection – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"ReceiptCellIdentifier"; SplitCheckCollectionCell *cell = (SplitCheckCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; cell.cellName.text = [NSString stringWithFormat:@"%@%i",@"#",indexPath.row+1]; return cell; } 在UICollectionViewCell的实现中: @implementation SplitCheckCollectionCell – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { NSArray *arrayOfViews = […]

主队列上的dispatch_sync在unit testing中挂起

我有一些麻烦的unit testing一些大的中央调度代码与内置的Xcodeunit testing框架SenTestingKit。 我设法解决了我的问题。 我有一个unit testing,build立一个块,并试图在主线程上执行它。 但是,该块从未实际执行,所以testing挂起,因为它是一个同步调度。 – (void)testSample { dispatch_sync(dispatch_get_main_queue(), ^(void) { NSLog(@"on main thread!"); }); STFail(@"FAIL!"); } testing环境是什么造成这个挂起?

我怎样才能在UICollectionView中居中行?

我有一个随机细胞UICollectionView 。 有什么方法可以让我排成行吗? 这是默认情况下的样子: [ xxxxxx ] [ xxxxxx ] [ xx ] 以下是所需的布局: [ xxxxx ] [ xxxxx ] [ xx ]

UICollectionView单元格select和单元重用

在select细胞时,我想要处理改变细胞的外观。 我想到了委托方法collectionView:didSelectItemAtIndexPath: & collectionView:didDeselectItemAtIndexPath:是我应该在哪里编辑单元格。 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { DatasetCell *datasetCell = (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath]; [datasetCell replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]]; datasetCell.backgroundColor = [UIColor skyBlueColor]; } 和 -(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { DatasetCell *datasetCell = (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath]; [datasetCell replaceHeaderGradientWith:[UIColor grayGradient]]; datasetCell.backgroundColor = [UIColor myDarkGrayColor]; } 这工作正常,除了单元格被重用。 如果我在索引(0,0)处select单元格,它会改变外观,但是当我向下滚动时,在选定状态中会有另一个单元格。 我相信我应该使用UICollectionViewCell方法-(void)prepareForReuse准备重用单元格(即将单元格外观设置为非选中状态),但是这给我带来了困难。 -(void)prepareForReuse { if ( self.selected ) { [self replaceHeaderGradientWith:[UIColor […]

在objective-c中release和dealloc之间的区别

当释放一个引用时,我已经看到release和dealloc被用作例子 -(void)dealloc { [foo release]; [nar dealloc]; [super dealloc]; } 我的问题是什么时候release被使用,何时dealloc被使用? 谢谢

UICollectionView自动调整高度

如何正确调整UICollectionView的大小,使其完全显示其内容? 我尝试了很多东西,包括设置框架,调用reloadData并使布局无效: self.collectionView.contentSize = CGSizeMake(300, 2000); self.collectionView.frame = CGRectMake(0, 0, 300, 2000); [self.collectionView reloadData]; [self.collectionView.collectionViewLayout invalidateLayout]; 但没有任何影响。 按下button后,我仍然可以看到初始视图,如下所示: 我有一个小的演示程序,我有一个数据源生成100个元素。 在界面生成器中,我最初将UICollectionView的大小设置为一个小值,以便不是所有元素都适合,之后我按下一个button,之后执行上面的代码。 我期望UICollectionView现在显示所有元素,但它不。 编辑:演示程序可以在https://github.com/mjdemilliano/TestUICollectionViewfind。 编辑2:我已经观察到帧更新在某个点丢失,因为如果我再次按下button,当前帧返回到旧值。 在button事件处理程序中添加一些日志语句之后,日志输出为: before: frame = {{0, 58}, {320, 331}}, contentSize = {320, 1190} update button pressed after: frame = {{0, 0}, {300, 2000}}, contentSize = {300, 2000} before: frame = {{0, 58}, {320, […]

在苹果的API中,“k”前缀是什么意思?

我已经运行了许多名为k + someVariableNameHere或k + APILibraryName(2Char) + someVariableNameHere的Core Foundationvariables的例子。 这个前缀K表示什么? 例子包括: kGLPFAStereo kCollectionLockBit kSetDebugOption

如何设置NSPredicate来查找具有nil属性的对象

我有一个ManagedObject class ,其中一个成员是NSDate 。 我想显示未设置date的类的所有对象。 我尝试使用这样的谓词: NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(date = NIL)"]; 但是我仍然在设置date地方得到对象。 build立这个谓词的正确方法是什么?

Objective-C的文档生成器?

是否有一个公认的Objective-C的文档生成器(类似于Ruby的RDoc)? 我见过Doxygen和ObjcDoc,我想知道哪个应用最广泛。