场景:用户点击视图控制器上的按钮.视图控制器是导航堆栈中最顶层的(显然).tap会调用另一个类上调用的实用程序类方法.在那里发生了一件坏事,我希望在控制返回到视图控制器之前在那里显示警报.
+ (void)myUtilityMethod {
// do stuff
// something bad happened, display an alert.
}
Run Code Online (Sandbox Code Playgroud)
这是可能的UIAlertView(但可能不太合适).
在这种情况下,你如何呈现一个UIAlertController,就在那里myUtilityMethod?
我是新手UICollectionView,我正在按照我在网上找到的教程,但我遇到了一个我无法弄清楚的错误.这是一个背景.
在调试器中,我可以看到以下情况:
numberOfSectionsInCollectionView:被叫,我返回1collectionView:numberOfItemsInSection: 被调用,我返回模型的大小(20)collectionView:layout:sizeForItemAtIndexPath: 为模型中的每个项目调用一次collectionView:layout:insetForSectionAtIndex: 叫做collectionView:cellForItemAtIndexPath: 被叫,它在这条线上崩溃了......
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)有这个错误......
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
Run Code Online (Sandbox Code Playgroud)
当我在该行暂停执行并检查控制台时,似乎有一个布局......
(lldb) po collectionView.collectionViewLayout
(UICollectionViewLayout *) $4 = 0x07180fd0 <UICollectionViewFlowLayout: 0x7180fd0>
Run Code Online (Sandbox Code Playgroud)
它UICollectionView是故事板中唯一一个场景的一部分.在viewController.m中,没有任何其他方法可以UICollectionView创建.
有没有人有任何想法?
我看到的问题是,当我创建一个UIContextualActionwith .destructive 并传入true时completionHandler,似乎有一个删除行的默认操作.
如果您从Xcode的模板创建一个新的Master-Detail应用程序并将此代码添加到MasterViewController...
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let testAction = UIContextualAction(style: .destructive, title: "Test") { (_, _, completionHandler) in
print("test")
completionHandler(true)
}
return UISwipeActionsConfiguration(actions: [testAction])
}
Run Code Online (Sandbox Code Playgroud)
您要滑动的行将被删除.请注意,没有代码更新表视图.此外,模型不会更新,如果向上滚动导致重新加载行,它将重新出现.
false在这种情况下传递不会删除该行.或使用.normal样式,true也不删除行.
.destructive并true导致默认情况下删除行.
谁能解释这种行为?为什么要删除行?
allowableMovement我的财产UILongPressGestureRecognizer似乎被忽略了.我使用Single View Application模板创建了一个新项目(Xcode 4.5.1,iOS 6),并在视图中添加了Long Press Gesture Recognizer.有一个插座和一个动作.这是action方法的代码:
- (IBAction)longPress:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStatePossible) NSLog(@"possible");
if (sender.state == UIGestureRecognizerStateBegan) NSLog(@"began");
if (sender.state == UIGestureRecognizerStateChanged) NSLog(@"changed");
if (sender.state == UIGestureRecognizerStateRecognized) NSLog(@"recognized");
if (sender.state == UIGestureRecognizerStateCancelled) NSLog(@"cancelled");
if (sender.state == UIGestureRecognizerStateFailed) NSLog(@"failed");
CGPoint locationInView = [sender locationInView:self.view];
NSLog(@"long press: allowableMovement= %f, x= %f, y= %f", sender.allowableMovement, locationInView.x, locationInView.y);
}
Run Code Online (Sandbox Code Playgroud)
如果我按下足够长的时间然后松开,我会在日志中得到这个:
2012-10-30 20:24:41.449 Long Press[1078:907] began
2012-10-30 20:24:41.455 Long Press[1078:907] long press: allowableMovement= 10.000000, x= 210.500000, y= 99.500000 …Run Code Online (Sandbox Code Playgroud) [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,如何在第一行的动画完成后执行第二行?
我试过这个......
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
{
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
}
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
还有这个...
[self.tableView beginUpdates];
{
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
}
[self.tableView endUpdates];
[self.tableView beginUpdates];
{
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}
Run Code Online (Sandbox Code Playgroud)
......但无论哪种方式,动画都是在同一时间发生的(当动画速度很慢时,动画真的很明显).
Crashlytics已安装在相关应用程序中,现已推出几个版本.它一直很好用.
但是在我们准备下一个版本时,Crashlytics已经停止在发布模式下报告崩溃.以下是自上次发布以来我可以想到的事情.
无论如何,所有这些更改崩溃仍然在Debug中正常报告.只是没有发布(在归档并上传到iTunes Connect后从TestFlight安装).
以下是我检查的内容:
在Fabric站点上,应用程序就在那里,版本和构建都在那里.当我点击Missing DSYMs时,它告诉我没有遗漏.
startWithAPIKey正在被召唤didFinishLaunchingWithOptions(在trojanfoe的问题之后添加).
api密钥是正确的.检查并仔细检查.
在构建脚本中,调试和发布之间没有(也从来没有)区别.它看起来像这样:
DEBUG_INFORMATION_FORMAT中已经设置为DWARF with dSYM File(在StormXX的问题之后添加):我错过了什么?
编辑:我想让大家都知道,自从我发布这个月以来,我一直在努力解决这个问题.现在github上有一个repo,展示了如何轻松实现这一目标并保持与KVC的兼容.没有理由在iOS上避免核心数据验证.它可能与Mac OS X不同,但它并不困难或困难.
我在视图控制器中编辑Person对象的属性.Person是NSManagedObject子类.我正在使用Core Data进行早期(保存前)验证.我正在使用这样的文档化validateValue:forKey:error:方法......
NSError *error;
BOOL isValid = [person validateValue:&firstNameString forKey:@"firstName" error:&error];
if (!isValid) {
...
}
Run Code Online (Sandbox Code Playgroud)
我在Xcode的Core Data模型编辑器中设置了最小值和最大值.当我验证firstName并且它太短时,我得到这样的错误......
Error Domain=NSCocoaErrorDomain Code=1670 "The operation couldn’t be completed. (Cocoa error 1670.)" UserInfo=0x8f44a90 {NSValidationErrorObject=<Event: 0xcb41a60> (entity: Event; id: 0xcb40d70 <x-coredata://ADB90708-BAD9-47D8-B722-E3B368598E94/Event/p1> ; data: {
firstName = B;
}), NSValidationErrorKey=firstName, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1670.), NSValidationErrorValue=B}
Run Code Online (Sandbox Code Playgroud)
但是我没有任何东西可以显示给用户.但错误代码在那里,所以我可以做这样的事情......
switch ([error code]) {
case NSValidationStringTooShortError:
errorMsg = @"First name must …Run Code Online (Sandbox Code Playgroud) 我知道如何创建一个,并且有很多关于Xcode项目的内容.这是一个更基本的问题.
假设我只是在本地工作,我还没有创建任何遥控器.
ios ×4
objective-c ×4
uitableview ×2
xcode ×2
core-data ×1
crashlytics ×1
git ×1
ios11 ×1
ios6 ×1
swipe ×1
testflight ×1
validation ×1