在ios8上,我正在使用核心数据表视图控制器,删除行后,我的部分页脚视图突然一直向下到底部UITableView.当我滚动表格视图时,页脚视图会返回到它的位置.如何解决这个问题,为什么会发生这种情况?
以下是代码以防万一.
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
if (self.beganUpdates)
{
[self.tableView endUpdates];
}
}
Run Code Online (Sandbox Code Playgroud) 有一个PFQuery的方法
PFQuery *query = [PFQuery queryWithClassName:@"class"];
[query whereKey:(NSString *)key containsAllObjectsInArray:(NSArray *)array];
Run Code Online (Sandbox Code Playgroud)
是否有类似的方法来定义数组中是否有指定的对象?喜欢
[query whereKey:(NSString *)key doesNotContainAllObjectsInArray:(NSArray *)array];
Run Code Online (Sandbox Code Playgroud)
如果不是,如何自己编写此方法?
当用户触摸UIButton时,它会变灰.什么苹果能做到这样的效果?当我的自定义UIButton突出显示时,我需要相同的效果.
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
AppDelegate* appDelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
if ([keyPath isEqualToString:@"highlighted"]){
UIButton *button = object;
if (button.isHighlighted) {
self.backgroundColor=[UIColor colorWithRed:36.0/255.0 green:153.0/255.0 blue:116.0/255.0 alpha:1];
}else{
self.backgroundColor=appDelegate.currentAppColor;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用此代码,但更改背景颜色不会影响任何子视图.我也需要它们变灰.
我正在创建一个性能高的应用程序,并且想知道编写相同代码的哪种方式在运行时运行得更快。
选项1:
let a = 1 + 2
self.doSomething(with: a)
self.doSomethingElse(with: a)
Run Code Online (Sandbox Code Playgroud)
选项2:
self.doSomething(with: 1 + 2)
self.doSomethingElse(with: 1 + 2)
Run Code Online (Sandbox Code Playgroud)
如果任何一个选项都更快,那么对结构体也是如此吗?例如
let a = CGPoint(x: 1, y: 1)
self.doSomething(with: a)
self.doSomethingElse(with: a)
Run Code Online (Sandbox Code Playgroud)
要么
self.doSomething(with: CGPoint(x: 1, y: 1))
self.doSomethingElse(with: CGPoint(x: 1, y: 1))
Run Code Online (Sandbox Code Playgroud)
编辑:添加了真实的场景
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
let currentPoint = touch.location(in: view)
let lastPoint = touch.previousLocation(in: view)
//////////
let newPoint1 = CGPoint(x: lastPoint.x - …Run Code Online (Sandbox Code Playgroud)