小编SFF*_*SFF的帖子

UISplitViewController - 以折叠模式在代码中解除/弹出详细视图控制器

从iOS8开始,我们可以在紧凑型和常规设备上使用UISplitViewController.这很棒,因为我不需要为iPhone和iPad创建两个不同的故事板,但是我遇到了一个问题.

如果拆分视图控制器在iPad上(如果折叠属性为NO),我可以简单地调用它来显示左侧的MasterVC.

self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
[self.splitViewController.displayModeButtonItem action];
Run Code Online (Sandbox Code Playgroud)

但如果它在iPhone上(如果折叠属性为YES),则忽略displayMode,并且不执行任何操作.

我无法弹出DetailVC,popToRootViewControllerAnimated因为DetailVC拥有自己的导航控制器.

如果没有像dismissViewControllerAnimated:completion:showDetail 一样的视图控制器的方法,Apple如何期望我们在折叠模式下的代码中显示MasterVC(关闭DetailVC)?我们将不胜感激.谢谢

iphone objective-c uisplitviewcontroller ios

11
推荐指数
2
解决办法
9684
查看次数

在Info.plist中找不到Bundle Display Name

如果我的应用程序的产品名称是"AppName:Some Description",我只想让"AppName"在iOS主屏幕上的应用程序图标下显示为名称.我做了一些搜索,发现了这个问题(在Xcode 4中更改了iPhone应用程序的名称).我正在使用Xcode 6,我在Info.plist中找不到Bundle Display Name.有人可以告诉我如何在Xcode 6中执行此操作.

谢谢

更新:

只需将光标放在Info.plist上,然后单击+按钮即可.选择"Bundle display name"并在值部分中插入名称.

在此输入图像描述

xcode cocoa-touch ios xcode6

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

CAGradientLayer不工作

我创建了一个新项目.我挂QuartzCore.framework和进口<QuartzCore/QuartzCore.h>ViewController.m.

这是代码.

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"view height %f", self.view.frame.size.height); // returns 667 on iPhone 6
    NSLog(@"view width %f", self.view.frame.size.width); // returns 375 on iPhone 6

    NSLog(@"layers count %lu", self.view.layer.sublayers.count); // returns 2

    // Gradient
    UIColor *colorOne = [UIColor blueColor];
    UIColor *colorTwo = [UIColor greenColor];
    NSArray *colorArray = @[colorOne, colorTwo];

    NSNumber *locationOne = [NSNumber numberWithFloat:0.0];
    NSNumber *locationTwo = [NSNumber numberWithFloat:1.0];
    NSArray *locationArray = @[locationOne, locationTwo];

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = self.view.frame; …
Run Code Online (Sandbox Code Playgroud)

objective-c calayer ios cagradientlayer

9
推荐指数
1
解决办法
4808
查看次数

UITableViewCell - 如何在重用之前重置内容

有一个烦人的错误,我无法解决.

我有一个CustomCell,在其中我有一个子视图,根据对象的值改变它的颜色.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    if (cell == nil) {        
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    MyObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];

    if ([object.redColor isEqualToNumber:[NSNumber numberWithBool:YES]]) {
        cell.colorView.backgroundColor = [UIColor redColor];
    }
    else {
        cell.colorView.backgroundColor = [UIColor clearColor];
    }       

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

这一切都正常,除非我redColor = YES从tableview中删除一行,并滚动显示不可见的行.变为可见的第一行(重用可重用单元格的第一行)具有红色,即使该行是redColor = NO.如果我再次滚动并隐藏单元格然后再次显示它,颜色将设置为clearColor,它应该是这样的.

我认为这是因为它重用了刚被删除的单元格.所以我在重用之前尝试重置单元格的内容.在CustomCell.m

- (void)prepareForReuse {
    [super prepareForReuse];

    self.clearsContextBeforeDrawing = YES;
    self.contentView.clearsContextBeforeDrawing …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

UITableViewCell重新排序清除子视图的背景颜色

这个问题已被问过几次,但似乎没有任何解决方案.

UITableView重新排序隐藏背景

重新排序时,UITableViewCell的子视图不可见

重新排序导致子视图的背景颜色清除

我有一个自定义的tableview单元格,里面有UILabel.当tableview处于编辑模式并且我拖动单元格重新排序时,UILabel的背景变为清晰的颜色.我还发现,如果我尝试重新排序所选单元格(我的tableview允许在编辑模式下进行多次选择),则子视图的背景颜色会保留.

我在CustomCell中尝试了以下方法,但是当拖动单元格时,它们都没有覆盖子视图的背景颜色.

我希望子视图的背景颜色保持不变.有没有我错过的方法?或者Apple以这种方式设计它?

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    if (selected) {
        if (self.isEditing) {
            self.customLabel.backgroundColor = [UIColor blueColor];
        }
        else {
            self.customLabel.backgroundColor = [UIColor blueColor];
        }
    }
    else {
            self.customLabel.backgroundColor = [UIColor blueColor];
    }
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];

    if (highlighted) {
        if (self.isEditing) {
            self.customLabel.backgroundColor = [UIColor blueColor];
        }
        else {
            self.customLabel.backgroundColor = [UIColor blueColor];
        }
    }
    else {
        self.customLabel.backgroundColor = [UIColor blueColor];
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview tableviewcell ios

5
推荐指数
2
解决办法
1101
查看次数

核心数据 - 具有一对多关系的 sectionNameKeyPath

我在使用关系创建 tableView 部分时遇到困难。

我有两个具有关系List <----->> Item 的实体。 在此处输入图片说明

我希望List是部分,而Item是行。我设置了sectionNameKeyPath一个关键路径@"itemList"。这是我的 fetchedResultsController 其余部分的样子

- (NSFetchedResultsController *)fetchedResultsController {

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    // Fetch Request
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
    [fetchRequest setFetchBatchSize:20];

    // Sort Descriptors
    NSSortDescriptor *itemSort = [[NSSortDescriptor alloc] initWithKey:@"displayOrderItem" ascending:YES];
    NSSortDescriptor *sectionSort = [[NSSortDescriptor alloc] initWithKey:@"displayOrderList" ascending:YES];
    NSArray *sortDescriptors = @[sectionSort, itemSort];
    [fetchRequest setSortDescriptors:sortDescriptors];

    // Fetched Results Controller
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"itemList" cacheName:nil]; …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c nsfetchedresultscontroller ios

3
推荐指数
1
解决办法
731
查看次数