小编cov*_*ack的帖子

setNeedsLayout仅在显示之后重新布局单元格

我有一个带有单元格的表格视图,有时会有一个可选的UI元素,有时它必须被删除.根据元素,调整标签大小.

当细胞初始化时,它比以后更窄.当我将数据设置到标签中时,将调用此代码cellForRowAtIndexPath:

if (someFlag) {
    // This causes layout to be invalidated
    [flagIcon removeFromSuperview];
    [cell setNeedsLayout];
}
Run Code Online (Sandbox Code Playgroud)

之后,单元格返回到表视图,并显示它.但是,该点的文本标签已调整其宽度,但不调整高度.大约一秒后调整高度,并且当已经显示所有单元格时,可以清楚地看到加加速度.

重要提示,这只是在初始创建前几个单元格时.一旦它们被重复使用,一切都很好,因为删除了可选视图,并且标签已经在之前的用法中正确调整了大小.

为什么在细胞setNeedsLayout显示之前没有完全重新铺设细胞?UIKit不应该在显示前检查无效布局吗?

如果我做

if (someFlag) {
    [flagIcon removeFromSuperview];
    [cell layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud)

一切都得到调整,但这似乎是一种不正确的编写代码的方式,我觉得我错过了其他的东西.


关于如何创建单元格的更多代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    [cell setData:model.items[indexPath.row] forMyself:YES];
    return cell;
}

// And in ProfileCell:
- (void)setData:(Entity *)data forMyself:(BOOL)forMe
{
    self.entity = data;

    [self.problematicLabel setText:data.attributedBody];
    // Set data in other subviews as well

    if (forMe) {
        // This causes …
Run Code Online (Sandbox Code Playgroud)

uitableview ios autolayout

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

如何将3个参数传递给@selector

我创建了一个动作

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)

就像这样:

self.moveAction = [CCSequence actions:                          
                   [CCMoveTo actionWithDuration:moveDuration position:touchLocation],
                   [CCCallFunc actionWithTarget:self selector:@selector(guyMoveEnded)],
                   nil
                  ];
Run Code Online (Sandbox Code Playgroud)

但现在,我想通过以下方式自动调用以下方法@selector:

-(void)guyMoveEnded:(BOOL)flag AndWhere:(CGPoint)where Andtime:(float)time{
    //do something...
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做?请帮助我,我对选择器感到困惑.

感谢名单!

iphone objective-c ios

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

核心数据无法识别选择器错误

我正在使用Core Data来保存一些字符串.我有以下类名为Results

Results.h

#import <CoreData/CoreData.h>

@interface Results : NSManagedObject

@property(nonatomic, retain) NSString *lessondate;
@property(nonatomic, retain) NSString *lesson;
@property(nonatomic, retain) NSString *location;
@property(nonatomic, retain) NSString *start;
@property(nonatomic, retain) NSString *end;

@end
Run Code Online (Sandbox Code Playgroud)

Results.m

#import "Results.h"

@implementation Results

@dynamic lessondate;
@dynamic lesson;
@dynamic location;
@dynamic start;
@dynamic end;

@end
Run Code Online (Sandbox Code Playgroud)

以下是我执行保存的代码:

-(void)saveLesson{

Results *result = (Results *)[NSEntityDescription insertNewObjectForEntityForName:@"Diary" inManagedObjectContext:managedObjectContext];

result.lessondate = calendarDateString;
result.lesson = [NSString stringWithFormat:@"%@", lessonText.text];
result.location = [NSString stringWithFormat:@"%@", locationTest.text];
result.start = [NSString stringWithFormat:@"%@", startTimeText.text];
result.end = [NSString stringWithFormat:@"%@", endTimeText.text];
NSError *error; …
Run Code Online (Sandbox Code Playgroud)

core-data nsmanagedobject ios

0
推荐指数
1
解决办法
2300
查看次数