小编Viv*_*ive的帖子

SwiftUI NavigationLink 立即加载目标视图,无需单击

使用以下代码:

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 swift swiftui

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

警告:尝试显示已经呈现的*on*(null)

这是我的第一个iOS应用程序.

所以我有一个UIVIewControllerUITableView在那里我有一个整合UISearchBarUISearchController以过滤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)

uitableview uiviewcontroller ios uistoryboardsegue swift

42
推荐指数
6
解决办法
4万
查看次数

CMutablePointer - 如何访问它?

任何人都可以解释如何访问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)

swift

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

圆形UIVisualEffectView

我有一张地图.在地图上,我想画一个小而模糊的圆圈.我实现了这样的事情:

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分钟.

objective-c blur ios uivisualeffectview

13
推荐指数
3
解决办法
8315
查看次数

使用fetchedResultController删除表视图中的行

在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)

但是这并没有改变崩溃和错误.它只是导致添加新行不再起作用.

objective-c tableview nsfetchedresultscontroller ios

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

无法在Swift 3的Collection扩展中使用indices.contains()

我在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)

问题是我不知道它在块内应该包含什么.请帮忙迁移它吗?

swift swift3 swift2.3

10
推荐指数
1
解决办法
2365
查看次数

不推荐使用的CLRegion方法 - 如何获得半径?

我正在使用该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已弃用.任何想法现在使用什么?我在文档中找不到任何有趣的东西.

objective-c core-location ios clregion

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

Fabric.io实现(AppDelegate)

我正在尝试将Fabric实现到我的应用程序中.问题是,应用程序无法正常工作,我不知道在AppDelegate中放置了什么代码.我在网上找不到任何有关我应该在那里实施的信息.任何人都可以给我一个提示,我应该在AppDelegate中实现哪些功能?

Fabric截图

iphone objective-c ios fabric.io

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

AutoLayout崩溃:位置锚点需要配对

该应用程序正在崩溃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)

crash objective-c ios autolayout

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

FetchResultController委托 - 不兼容的类型警告

我正在尝试使用基于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

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