小编an0*_*an0的帖子

如何在UITableView中初始选择一行

我找不到打电话selectRowAtIndexPath:animated:scrollPosition:最初选择一行的好地方UITableView.在初始化表视图控制器时,尚未加载表数据,因此在初始化后我无法立即进行选择UITableViewController(否则会发生超限异常).

select uitableview

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

使用Core Text的多语言布局中的行间距

属性字符串只有一个属性 - 17点Helvetica NeueUI字体 - 覆盖整个字符串.1~3行纯英语,4~6行是英汉混合,7~8行纯粹是中文.

然后使用CTFramesetter进行布局,并使用CTFrameDraw绘制结果框架.

// UIView subclass
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica NeueUI"), 17.f, NULL);
        _text = [[NSAttributedString alloc] initWithString:string attributes:
                 [NSDictionary dictionaryWithObject:(id)font forKey:(id)kCTFontAttributeName]];
        CFRelease(font);
        _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_text);
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathAddRect(path, NULL, self.bounds);
        _frame = CTFramesetterCreateFrame(_framesetter, CFRangeMake(0, 0), path, NULL);
        CGPathRelease(path);
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    // Flip the coordinate system.
    CGContextTranslateCTM(context, 0.f, self.bounds.size.height);
    CGContextScaleCTM(context, …
Run Code Online (Sandbox Code Playgroud)

core-text ios

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

我可以依靠nil UIView为其框架返回CGRectZero吗?

是的,我看到了这个:

如果该方法返回一个结构,如Mac OS X ABI函数调用指南所定义的那样在寄存器中返回,则发送给nil的消息将返回结构中每个字段的0.0.其他结构数据类型不会用零填充.

我只是不明白.

objective-c ios

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

针对初始零大小视图的不可满足的布局约束更好的解决方法?

虽然没有后果,但看到这些警告是非常烦人的:

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 and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)  (
    "<NSLayoutConstraint:0x19288a20 V:|-(6)-[UILabel:0x19288640]   (Names: '|':_UITableViewHeaderFooterContentView:0x192885b0 )>",
    "<NSLayoutConstraint:0x19288a70 V:[UILabel:0x19288640]-(6)-|   (Names: '|':_UITableViewHeaderFooterContentView:0x192885b0 …
Run Code Online (Sandbox Code Playgroud)

ios autolayout

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

我可以使用多少剩余内存?

我的问题:

我在我的应用程序中处理图像流.有些图像真的很大.因此,在处理图像之前,我需要一种方法来判断是否可以使用剩余的内存来处理它.但我怎么知道我可以使用多少剩余内存?

我的研究结果:

  1. 我可以通过此UIDevice扩展知道总内存用户内存.
  2. 我可以知道虚拟,居民,有线,活跃,不活跃,以及可用内存通过.

我的日志:

2013-12-13 11:15:05.966 Total Memory: 505 MB    User Memory: 434.3 MB
2013-12-13 11:15:05.967 Virtual: 348.7 MB   Resident: 6.3 MB    Free: 254.1 MB  Inactive: 35 MB Active: 70.7 MB Wired: 70.6 MB
2013-12-13 11:15:57.742 Virtual: 530.2 MB   Resident: 95.2 MB   Free: 160.6 MB  Inactive: 45 MB Active: 74.1 MB Wired: 72 MB
2013-12-13 11:16:41.320 Virtual: 569.2 …
Run Code Online (Sandbox Code Playgroud)

memory ios

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

如何在NSTextAttachment上禁用交互?

在具有editable = YES和selectable = NO的UITextView中,我想禁用NSTextAttachments上的交互.更具体地说,我不希望在NSTextAttachments上长按以突出显示附件图像.我希望将这些长按手势作为普通文本选择手势传递给UITextView.

我尝试过: textView:shouldInteractWithTextAttachment:inRange:可以阻止动作表,但不能阻止附件图像的临时高亮,也不能使这些长按作为文本选择手势处理.

uitextview nstextattachment ios

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

是否在更改视图大小时调用layoutSubviews?

在我的印象中,使用autoresizesSubviews = YES,每次更改视图的大小时都应调用layoutSubviews.但我发现我的观点并非如此.我的期望是错的吗?

cocoa-touch uiview ios

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

如何为NSManagedObject做完美的KVO?

这里的完美KVO包括两部分:正确添加观察者并正确删除观察者.

故事:

  1. 我使用一个UITableViewCell(单元格)来显示一个NSManagedObject(对象).
  2. 每个对象都有一些需要通过其单元格观察的动态属性.
  3. 并非所有对象都具有相同的观察属性集.我有选择地添加关键路径观察器,如下所示:

    if(object.thumbnail_pic_url)[object addObserver:cell forKeyPath:@"thumbnail_picture"options:0 context:NULL];

  4. 对象可以删除.删除对象时,我必须删除观察者.数据库非常庞大和复杂,所以我绝对不想注册所有单元格来接收moc通知,如NSManagedObjectContextObjectsDidChangeNotification.但是如果必须的话,我可以接受在对象中添加一个单元格ivar,即使它再次成为好的Modle-View-Controller设计模式.

问题:在删除对象时,如何正确删除对象中所有已注册密钥路径的观察者(单元格)?

事实上,这是一个很大的问题,可以分为两个小问题:

  1. 观察者删除代码的最佳位置在哪里?
  2. 如何确定要注销的关键路径?在删除对象后我无法查询其属性 - 这将导致无法填充的错误,因此我无法编写如下代码:

    if(object.thumbnail_pic_url)[object removeObserver:cell forKeyPath:@"thumbnail_picture"];

并且我不能盲目地删除未注册的密钥路径的观察者 - 异常(无法删除关键路径"thumbnail_picture"的观察者,因为它未被注册为观察者.)将被抛出.

core-data key-value-observing nsmanagedobject ios

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

如何拦截长按UIWebView中的链接?

我想提供自己的操作表或弹出窗口,不希望默认系统一.

请注意:

  1. 我问长按点击.
  2. 我需要知道长按的链接的URL.

javascript iphone uiwebview ipad ios

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

声明方法参数__autoreleasing有什么好处?

根据过渡到ARC发行说明:

__autoreleasing用于表示通过引用(id*)传递的参数,并在返回时自动释放.

例如:

-(BOOL)performOperationWithError:(NSError * __autoreleasing *)error;

但与上述相比,上述优点有哪些:

-(BOOL)performOperationWithError:(NSError * __strong *)error;


更新:

几个答案是指临时VAR招编译器处理为var和参数之间的不匹配的优势__autoreleasing.我不明白为什么编译器不能为__strong参数做同样的技巧.我的意思是,对于__weakvar和__strong参数,编译器可以类似地执行此操作:

NSError * __weak error;
NSError * __strong tmp = error;
BOOL OK = [myObject performOperationWithError:&tmp];
error = tmp;
if (!OK) {
    // Report the error.
}
Run Code Online (Sandbox Code Playgroud)

编译器知道-(BOOL)performOperationWithError:(NSError * __strong *)error;返回一个强引用(+1),所以它像任何new-family方法一样处理它.由于tmp生活在相同的范围内error,编译器可以合理地保持它活着,只要error这样__weak引用(error)现在由__strongreference(tmp)支持,并且在范围结束之前不会无效.

objective-c automatic-ref-counting

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