小编And*_*rov的帖子

如何在UIBarbutton项目上添加徽章?

嗨朋友是iphone开发的新手.我很难在右侧的UIBarbutton项目上添加徽章值.我试过但我无法解决这个问题.谁能帮我.

提前致谢!

uinavigationbar uibarbuttonitem badge ios

33
推荐指数
6
解决办法
4万
查看次数

如何使deleteRowsAtIndexPaths:使用GenericTableViewController?

我正在使用Matt Gallagher GenericTableViewController控制我的想法UITableViews.我的数据源是NSFetchedResultsController.

http://cocoawithlove.com/2008/12/heterogeneous-cells-in.html

一切都运行正常,直到我尝试删除一个单元格.

我在View Controller中有以下代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

  if (editingStyle == UITableViewCellEditingStyleDelete) {

        // Delete the managed object.
        NSManagedObjectContext *context = [wineryController managedObjectContext];
        [context deleteObject:[wineryController objectAtIndexPath:indexPath]];

        NSError *error;
        if (![context save:&error]) {
            // Handle the error.
        }
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }   
}
Run Code Online (Sandbox Code Playgroud)

最后一行因控制台中相当冗长的解释而崩溃:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',  
reason: 'Invalid update: invalid number of rows in section 0.  The number of rows   
contained in an …

iphone cocoa-touch objective-c

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

将uiview捕获到uiimage时,蒙版不起作用

我有一个UIView我想保存的UIImage.我这样做UIGraphicsBeginImageContext,它工作正常.但是当我将掩码应用于(view/layer.mask)中的图像时,我捕获的图像UIGraphicsBeginImageContext是错误的(在运行应用程序时屏蔽是有效的,但在尝试UIImage从a 获取时却没有UIView).有人遇到类似的问题?

mask calayer uiview uiimage ios

11
推荐指数
1
解决办法
1616
查看次数

如何使用自定义布局修复UICollectionView中的可见单元格滚动?

我正在研究受UIPickerView启发的自定义值选择器.它看起来像这样: 技术原型屏幕1

正如您所看到的,此拾取器的主要特征之一是中央单元应该比其他单元更宽,以使其邻居在中央框架旁边可见.当您使用平移手势滚动选择器时,它应该动态更改中心值并根据上面的逻辑调整单元格.它的工作原理非常完美: 技术原型屏幕2

问题在于轻击手势.当用户通过点击它来选择选择器上的任何项目时,选择器试图滚动到该项目.但是,由于自定义布局UIScrollView滚动到错误点,因此它的偏移被更改了.看起来像这样: 技术原型屏幕3

当我尝试滚动到屏幕外单元格时,一切正常 - 该单元格不受布局的影响,并且它的坐标是正确的.这个问题仅针对可见细胞而上升.我完全没有任何关于如何解决这个问题的想法.你可以在这里找到整个项目:Carousel Collection View Test Project

请在下面找到一些重要的代码.

// CarouselLayout.m

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
    NSArray *array = [super layoutAttributesForElementsInRect:rect];
    CGRect visibleRect;
    visibleRect.origin = self.collectionView.contentOffset;
    visibleRect.size = self.collectionView.bounds.size;

    CGRect center = CGRectMake(CGRectGetMidX(visibleRect) - 1.0, 0.0, 2.0, CGRectGetHeight(visibleRect));
    CGFloat coreWidth = CGRectGetWidth(self.centralFrame) / 3.0;

    for (UICollectionViewLayoutAttributes *attributes in array) {
        if (CGRectIntersectsRect(attributes.frame, rect)){
            CGFloat distance = CGRectGetMidX(visibleRect) - attributes.center.x;
            CGFloat offset = 0.0;
            CGRect coreFrame = CGRectMake(attributes.center.x - (coreWidth / 2.0), 0.0, coreWidth, CGRectGetHeight(self.centralFrame));
            if (CGRectIntersectsRect(center, coreFrame)) { …
Run Code Online (Sandbox Code Playgroud)

objective-c custom-component ios uicollectionview uicollectionviewlayout

8
推荐指数
1
解决办法
6344
查看次数