我试图摆脱Interface Builder中那些烦人的警告,但我不明白它在抱怨什么(所有Interface Builder,没有代码):

我指定了一个固定的固定高度和固定的距离到右边和顶部.
然而警告告诉我
Needs Constraints for: Y position, height
Needs Constraints for: X position, width
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下这些限制是不够的?
编辑
此外,当使用"自动"添加约束命令时,它什么都不做,错误仍然存在.
我遇到了最怪异的显示错误UISearchBar.
这是我的代码在另一个应用程序中完美运行.(我在代码中创建搜索栏,因为xib文件不可行.)
searchBar = [[UISearchBar alloc] initWithFrame:
CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
searchBar.delegate = self;
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
self.tableView.tableHeaderView = searchBar;
Run Code Online (Sandbox Code Playgroud)
搜索功能等工作正常.但奇怪的是,搜索栏在设备和模拟器上都是这样的:
searchBar.placeholder或searchBar.prompt以@""或nil不移除此"搜索"占位符.(但是,a searchBar.placeholder = @"FooBar";有帮助吗?最紧迫的问题是将文本置于右侧.
我创建了一个包含页面控件的uiscrollview,它从资源包中加载图像..一切正常.可以滚动浏览不同的图像..问题是如果我点击相应的页面控件(点),我无法导航相应的图像....你们可以帮助我下面的代码...下面的代码工作得很好
// Email.h
@interface Email : UIViewController<UIScrollViewDelegate>
{
UIPageControl *pageControl;
UIScrollView *scroller;
}
@property (nonatomic,retain)IBOutlet UIPageControl *pageControl;
@property (nonatomic,retain)IBOutlet UIScrollView *scroller;
-(IBAction)clickPageControl:(id)sender;
@end
// Email.m
@implementation Email
@synthesize pageControl,scroller;
-(IBAction)clickPageControl:(id)sender
{
int page=pageControl.currentPage;
CGRect frame=scroller.frame;
frame.origin.x=frame.size.width=page;
frame.origin.y=0;
[scroller scrollRectToVisible:frame animated:YES];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int page = scrollView.contentOffset.x/scrollView.frame.size.width;
pageControl.currentPage=page;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title=@"Press Photos";
for (int i=1; i<10; i++)
{
UIImageView *images=[[UIImageView alloc]initWithImage:
[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];
images.frame=CGRectMake((i-1)*320, 0, 320, 460);
[scroller addSubview:images];
[images release];
}
scroller.delegate=self;
scroller.contentSize=CGSizeMake(320*9, …Run Code Online (Sandbox Code Playgroud) 我又遇到了另一个问题,但很长一段时间后.
这次我有数据库(核心数据),其属性numbers包含整数,如213879,123,4,345,56567等.
我需要以类似alphabetically顺序的升序数字顺序获取数据.
我这样做的方式如下,
fetchRequest.sortDescriptors=[NSArray arrayWithObject:
[NSSortDescriptor sortDescriptorWithKey:@"numbers"
ascending:YES
selector:@selector(compare:)]];
Run Code Online (Sandbox Code Playgroud)
但不幸的是它仅仅比较每个数字的第1位,意味着如果有2个号码,如123和321,它将比较1 (first digit of first number)与3 (first digit of second number)和排序.
它混淆了当谈到123和111(所有数字的相同第一位数).
如果我做错了或者SortDescriptor以这种方式工作?我需要解决方案来123,133,213,451,516同样按升序对数字进行排序.
要记住的事实
实际上,属性numbers将包含数字大于6的整数.例如1234567,234568,235481
感谢所有在预期中帮助我的人.
一个相当复杂的问题,寻找一个优雅的解决方案:
一个UITableViewCell子类有一个UILabel在左边,一个UITextView在右边.标签和文本视图都具有动态内容.我使用文本视图而不是另一个标签,因为我需要地址链接识别.
标签具有比文本视图更高的抗压性,因此其右边缘将根据需要向右扩展(达到一定限制).文本视图的宽度将被压缩.文本视图设置为自动换行以向下扩展.
因为文本视图本身是a UIScrollView,动态大小的表视图单元视图的正常自动维度机制将不起作用(即使用UITableViewAutomaticDimension).因此,我试图实施heightForRowAtIndexPath.为了确定必要的高度,我认为只需要:
有了这些信息,我估计,我可以使用sizeThatFits辅助对象来确定必要的高度.
但是,我不愿意将标签和文本视图之间的水平边距硬编码到我的尺寸计算中,所以理论上我还需要NSLayoutConstraint插座
这看起来真的很疯狂!在我写这个实现时,我问自己是否有更简单的方法来实现同样的目标.(这就是为什么我还没有编写代码来发布这里.)毕竟,这里唯一的难题是如何获得文本视图的可用宽度,但是到达那里的方式似乎过于复杂.
想要简洁优雅的解决方案吗?
附注:必须在渲染单元格之前计算.此外,设置文本视图scrollingEnabled以false在使用时产生奇怪的结果sizeThatFits.
[filteredArray filterUsingPredicate:
[NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] %@", searchText]];
Run Code Online (Sandbox Code Playgroud)
filteredArray包含简单的NSStrings.[你好,我的,上,下,七等...];
它将提供所有以字符串开头的字符串searchText.
但是,如果字符串将是"我的名字是"等单词的组合,和searchText = name.将一个什么NSPredicate样子来实现这一目标?
更新:如果我想要一个结果searchText = name,但如果不想要结果,它将如何searchText = ame?也许是这样的:
[filteredArray filterUsingPredicate:
[NSPredicate predicateWithFormat:
@"self BEGINSWITH[cd] %@ or self CONTENTS[cd] %@",
searchText, searchText]];
Run Code Online (Sandbox Code Playgroud)
但它应该首先显示searchText以及包含的字符串开头的字符串searchText.
这是我的对象图的相关部分:
Store <-->> Gift <<--> Person <<-->> Tag
Run Code Online (Sandbox Code Playgroud)
我希望能够通过tag.filtering属性过滤商店,如下所示:
ANY gifts.person.tags.filtering == YES
Run Code Online (Sandbox Code Playgroud)
但我理解为什么这不起作用,因为对一对多密钥的限制.所以我试图使用一组嵌套的SUBQUERY谓词,如下所示:
NSPredicate* filterPredicate = [NSPredicate predicateWithFormat:
@"(0 != SUBQUERY(gifts, $x,
(0 != SUBQUERY($x.person.tags, $y, $y.filtering==YES).@count)).@count)"];
Run Code Online (Sandbox Code Playgroud)
这在运行时失败并出现错误:
"SQLite error code:1, 'no such column: t3.ZFILTERING'"
Run Code Online (Sandbox Code Playgroud)
看起来我在正确的轨道上,但是找不到任何其他使用相同语法的示例.我错过了什么?
我在Swift中构建了一个OS X命令行工具(Objective-C中的同样问题),用于下载某些文件.我正在尝试使用下载进度更新命令行.不幸的是,我无法阻止print语句跳转到下一行.
根据我的研究,回车\r应该跳到同一行的开头(同时\n插入一条新线).
所有测试都在OS X终端应用程序中执行,而不是在Xcode控制台上执行.
let logString = String(format: "%2i%% %.2fM \r", percentage, megaBytes)
print(logString)
Run Code Online (Sandbox Code Playgroud)
仍然,显示器插入一个新行.怎么预防这个?
我的应用程序在表格视图中搜索期间挂起。
就其价值而言,视图层次结构非常复杂,涉及弹出窗口以及过滤器和搜索栏等。我正在审查所有这些可能性。
但是,在调用reloadData.
这是我停止程序并查看主线程时得到的结果:

你可以看到——它涉及到 UIView、CALayer、CATransaction。我不知道如何回到我的控制器类来找到有问题的代码。
欢迎任何提示、建议、大胆猜测!
编辑 这里有更多 - 当我在其他随机点中断时会出现更多类。

所以,我在JSON中有以下结构,我理解它是一个键/值对对象的数组:
{
"notification": [
{
"uid": "20",
"count": "4"
},
{
"uid": "48",
"count": "0"
},
{
"uid": "49",
"count": "0"
},
{
"uid": "53",
"count": "0"
}
]
}
Run Code Online (Sandbox Code Playgroud)
使用SBJson解析这将导致一组字典,每个字典具有一个键/值对.
我想将所有这些词典"内爆"到一个包含许多键/值对的字典中.顺便说一下,不要担心重复.
这是最好的方法吗?我如何遍历NSDictionary,一次访问一个项目并提取它的关键和价值?
有什么想法吗?
谢谢.
--Conor
ios ×6
objective-c ×5
autolayout ×2
core-data ×2
ipad ×2
iphone ×2
nspredicate ×2
swift ×2
calayer ×1
cocoa ×1
constraints ×1
ios6 ×1
macos ×1
newline ×1
nsdictionary ×1
nsnumber ×1
uisearchbar ×1
uitableview ×1
uitextfield ×1
uiview ×1
xcode ×1