使用以下代码:
struct HomeView: View {
var body: some View {
NavigationView {
List(dataTypes) { dataType in
NavigationLink(destination: AnotherView()) {
HomeViewRow(dataType: dataType)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当HomeView
出现时,NavigationLink
立即加载AnotherView
. 结果,所有AnotherView
依赖项也被加载,即使它在屏幕上还不可见。用户必须单击该行才能使其出现。MyAnotherView
包含一个DataSource
,在那里发生各种事情。问题是此时DataSource
已加载整体,包括一些计时器等。
难道我做错了什么..?如何以这种方式处理它,AnotherView
一旦用户按下它就会加载HomeViewRow
?
这是我的第一个iOS应用程序.
所以我有一个UIVIewController
与UITableView
在那里我有一个整合UISearchBar
和UISearchController
以过滤TableCells显示
override func viewDidLoad() {
menuBar.delegate = self
table.dataSource = self
table.delegate = self
let nib = UINib(nibName: "ItemCellTableViewCell", bundle: nil)
table.registerNib(nib, forCellReuseIdentifier: "Cell")
let searchButton = UIBarButtonItem(barButtonSystemItem: .Search, target: self, action: "search:")
menuBar.topItem?.leftBarButtonItem = searchButton
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
return controller
})()
self.table.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
我也使用模态segue来打开元素ViewController
,我将在其中显示元素的细节.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.index = indexPath.row
self.performSegueWithIdentifier("ItemDetailFromHome", sender: self) …
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释如何访问CMutablePointer<CGPoint>
下面提到的?我找不到它的语法.它曾经是->
中Objective-C
,但在这里没有我的解决方案的工作.此链接中提供的解决方案与我需要找到的方式相反.
func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: CMutablePointer<CGPoint>) {
let newPage = targetContentOffset->x + 1;
}
Run Code Online (Sandbox Code Playgroud) 我有一张地图.在地图上,我想画一个小而模糊的圆圈.我实现了这样的事情:
UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:visualEffect];
[self addSubview:self.visualEffectView];
Run Code Online (Sandbox Code Playgroud)
然后在layoutSubviews
:
[self.visualEffectView setFrame:CGRectMake(0.f, 0.f, 20.f, 20.f];
Run Code Online (Sandbox Code Playgroud)
现在的问题是围绕这个观点.我试过了:
[self.visualEffectView.layer setCornerRadius:10.f];
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.另一个尝试是(基于SOF问题):
CAShapeLayer *mask = [CAShapeLayer layer];
mask.path = [UIBezierPath bezierPathWithOvalInRect:self.visualEffectView.bounds].CGPath;
self.visualEffectView.layer.mask = mask;
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,它visualEffectView
是圆的,但不会模糊:/.有没有办法使它工作?
顺便说一下:我已经尝试过了FXBlurView
,但是效果非常慢,我无法接受我的应用只能在iPhone 5上加载地图+模糊约1分钟.
在swype删除期间(此方法的大多数importatnt行):
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
Table *deleteRow = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.managedObjectContext deleteObject:deleteRow];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Run Code Online (Sandbox Code Playgroud)
删除行时出现此错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第2节中的行数无效.更新
后的现有部分中包含的行数(1)必须等于该行中包含的行数在更新(1)之前的部分,加上或减去从该部分插入或删除的行数(0插入,1删除)和加或减移入或移出该部分的行数(0移入,0移动)出)."
如果我评论最后一行代码([tableView deleteRowsAtIndexPaths:...]
)一切正常(但我必须刷新视图才能看到该行被删除).
怎么做得好......?
编辑:考虑@Kyr Dunenkoff回应我添加:
- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
UITableView *tableV = [self tableView];
switch(type) {
case NSFetchedResultsChangeDelete:
[tableV deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController*)controller
{
[[self tableView] endUpdates];
}
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller
{
[[self tableView] beginUpdates];
}
Run Code Online (Sandbox Code Playgroud)
但是这并没有改变崩溃和错误.它只是导致添加新行不再起作用.
我在Swift 2.3中写了以下扩展:
extension CollectionType {
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
subscript (safe index: Index) -> Generator.Element? {
return indices.contains(index) ? self[index] : nil
}
}
Run Code Online (Sandbox Code Playgroud)
但事实证明,Swift 3.0没有contains()
功能.相反,它为我提供了以下语法:
indices.contains(where: { (<#Self.Indices.Iterator.Element#>) -> Bool in
<# code ??? what should it do??? #>
})
Run Code Online (Sandbox Code Playgroud)
问题是我不知道它在块内应该包含什么.请帮忙迁移它吗?
我正在使用该geocodeAddressString:completionHandler:
方法,该方法返回CLPlacemarks数组.我必须获得纬度,经度,助记名称和半径.虽然获得前3个很容易:
double lat = placemark.location.coordinate.latitude;
double lng = placemark.location.coordinate.longitude;
NSString *name = [NSString stringWithFormat:@"%@", ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO)]
Run Code Online (Sandbox Code Playgroud)
我现在不知道如何获得半径,因为placemark.region.radius
已弃用.任何想法现在使用什么?我在文档中找不到任何有趣的东西.
我正在尝试将Fabric实现到我的应用程序中.问题是,应用程序无法正常工作,我不知道在AppDelegate中放置了什么代码.我在网上找不到任何有关我应该在那里实施的信息.任何人都可以给我一个提示,我应该在AppDelegate中实现哪些功能?
该应用程序正在崩溃Location anchors require being paired.
.我想修复它,但无论我用这个视图手动测试应用程序多少次,我都没遇到过崩溃(只登录Crashlytics).任何人都知道这里可能出现什么问题,在什么情况下可能会发生崩溃?
该属性centerYConstraint
是必需的,因为稍后它允许用户向上/向下移动视图.
部分MyView.m
文件.崩溃发生在设置上self.centerYConstraint
.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.centerYConstraint = [self.view.centerYAnchor constraintEqualToAnchor:self.parentViewController.view.centerYAnchor
constant:self.view.center.y - self.parentViewController.view.center.y];
self.centerYConstraint.active = YES;
}
Run Code Online (Sandbox Code Playgroud)
崩溃日志:
Fatal Exception: NSInvalidArgumentException
NSLayoutConstraint for <NSLayoutYAxisAnchor:0x16764ae0 "MyView:0x18e6b900.centerY">:
A constraint cannot be made from <NSLayoutYAxisAnchor:0x16764ae0 "MyView:0x18e6b900.centerY"> to a constant.
Location anchors require being paired.
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用基于iCloud示例的 NSFetchedResultController将我的CoreData连接到iCloud .
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"date" cacheName:@"Root1"];
aFetchedResultsController.delegate = self;
Run Code Online (Sandbox Code Playgroud)
但是我在第二行得到了这样的警告:警告:语义问题:将'RootViewController*const __strong'传递给不兼容类型'id'的参数.我认为将委托设置为自我应该没问题,但事实并非如此.有人可以帮忙吗?
cocoa-touch delegates objective-c nsfetchedresultscontroller
ios ×7
objective-c ×6
swift ×4
autolayout ×1
blur ×1
clregion ×1
cocoa-touch ×1
crash ×1
delegates ×1
fabric.io ×1
iphone ×1
swift2.3 ×1
swift3 ×1
swiftui ×1
tableview ×1
uitableview ×1