小编Jos*_*ane的帖子

以编程方式将UINavigationBar添加到UIView?

我试图以编程方式将UINavigationBar添加到UIView并取得如此成功,并且无法弄明白.我试图在我的UIView子类中添加它,它只是在我运行我的应用程序时没有显示.

这是我的代码:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, headerHeight)];
    [navBar setBackgroundColor:[UIColor blueColor]];
    [self addSubview:navBar];

    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"done" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];

    UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"categories"];
    [navItem setRightBarButtonItem:doneItem animated:YES];
    [navBar setItems:[NSArray arrayWithObject:navItem] animated:YES];
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationbar uiview ios

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

在两个NSDate之间获得准确的时间差?

有没有办法找出两者之间的准确差异NSDate?

我找到了解决方案,但它们不够准确.我需要考虑夏令时,不同月份的天数不同等等.

一个简单的计算,如/ 60/60/24等,可以计算出分钟,小时和天数,但不考虑它们.

让我们说我需要弄清楚现在([NSDate date])和12月25日晚上10点22分(用户使用日期选择器选择的日期[datePicker date])之间的差异,作为一个例子,我该怎么做?
知道确切的时差并不是关键,只要我有几天,几个月和几年的准确差异就可以了.

cocoa-touch objective-c nsdate ios

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

带有Transition的UIModalPresentationCurrentContext?

我试图模态呈现如下的视图控制器:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"addPopover"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)

现在使用UIModalPresentationCurrentContext手段我可以使用透明背景显示此视图,并查看新视图背后的另一个视图.然而,它阻止我能够通过转换呈现它.

有什么想法吗?或者我如何解决这个问题?谢谢.

iphone objective-c ipad uimodaltransitionstyle uimodalpresentationstyle

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

使UITextView的部分不可删除?

我有一个UITextView,需要使特定部分不可删除.它是视图文本的前10个字符.

希望你能提供帮助,我只是想要它,这样如果用户点击键盘上的删除键,它就会在它到达时说停止说第10个字符.

希望你能帮忙,谢谢.

编辑:

Progress1感谢您到目前为止的答案,让我进一步了解一下细节.

让我们说前缀是'123456789:'.我希望能够在这个前缀之后的任何地方输入,但它根本不可编辑,因此'123456789:'不应该被改变.Fichek的答案完美地做到了这一点,但是前缀并不总是存在,所以如何检测它何时不在textview中?我认为if语句做了这个,但似乎没有.

cocoa-touch objective-c uitextview ios

9
推荐指数
2
解决办法
3539
查看次数

创建NSManagedObject而不保存?

可能重复:
存储但是不要将NSManagedObject保存到CoreData?

我需要制作NSManagedObject而不保存它,我该怎么做?

我想这样做的原因是应用程序有一个设置,用户输入他们的详细信息,但我只想保存对象,如果他们完成设置(他们可以选择取消,在这种情况下,对象需要是丢弃而不保存,这就是为什么我不想直接插入它.

我尝试在没有上下文的情况下插入一个,但应用程序崩溃了.

我尝试过以下方法:

GuestInfo *guest;
guest = (GuestInfo *)[NSEntityDescription insertNewObjectForEntityForName:@"GuestInfo" inManagedObjectContext:nil];
Run Code Online (Sandbox Code Playgroud)

这会导致崩溃,并显示以下错误消息:

'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'GuestInfo''
Run Code Online (Sandbox Code Playgroud)

core-data objective-c nsmanagedobject nsmanagedobjectcontext ios

9
推荐指数
2
解决办法
8173
查看次数

如何在NSArray中对数字进行排序?

我不能拼凑如何做到这一点.

我从一个plist中获取我的数组,这个数组充满了数字(在plist中设置).现在我需要做的就是对它们进行排序,使它们下降,但我无法解决它.

cocoa-touch objective-c plist ios

9
推荐指数
4
解决办法
2万
查看次数

UITableView部分背景?

是否可以在UITableView中的一个部分后面使用背景图像?

我想不出如何实现这一点,任何帮助都将不胜感激,谢谢.

iphone objective-c uitableview ios

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

UICollectionView registerCell - 空白单元格

我刚刚第一次开始玩UICollectionView.似乎工作得很好,但有一个问题和一个问题.

我有如下的UICollectionView设置和自定义单元格:

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ContactCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    cell.nameLbl.text = @"text";

    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(145, 95);
}

- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}
Run Code Online (Sandbox Code Playgroud)

所以这都是花花公子,但我已将此行添加到viewDidLoad:

[collectionView registerClass:[ContactCell class] forCellWithReuseIdentifier:@"Cell"];
Run Code Online (Sandbox Code Playgroud)

这引起了麻烦,我不明白为什么.当我启用此行时,我的所有单元格都会变为空白.怎么会?我错过了什么?

另外,据我所知,如果该行启用可重用单元格,为什么我必须使用集合视图而不必在表格视图中?

iphone objective-c ipad uicollectionview

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

另一个UIView下面的addSubview

我希望能够在另一个已经存在的UIView下面添加Subview,我该怎么做?我一直没能找到任何东西.

iphone objective-c uiview addsubview

9
推荐指数
2
解决办法
9052
查看次数

UICollectionViewCell自动布局

我UICollectionViewCell在故事板中编写了一个简单的自定义,我也以编程方式完成了相同的结果.

它有一个单数UIImageView和两个UILabels,如下:

          <--UIIMAGEVIEW-->          <--UILABEL-------->
|-(10px)- |               | -(10px)-                     -(10px)-|
          <--------------->          <--UILABEL-------->
Run Code Online (Sandbox Code Playgroud)

图像位于左侧,然后右侧是两个上下标签.

每个间隔有10个像素间隙,并且全部以单元Y轴为中心.然后标签有一个常数来偏离中心(向上和向下).

图像的高度和宽度固定为44px,标签的固定高度为20px(宽度灵活).

约束按预期工作,永远不会破坏应用程序,但它们总是在下面吐出这个恼人的控制台日志信息,因为它们显然正在破坏.

如果我将此行添加到我的UICollectionViewCell子类中,则约束不再中断并吐出控制台错误,但它们在屏幕上完全被破坏.

[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
Run Code Online (Sandbox Code Playgroud)

有线索吗?这看起来很不合逻辑!

这是控制台错误代码:

2014-10-25 18:28:14.273 Air Plan[1579:580797] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios autolayout uicollectionviewcell

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