小编Tri*_*ton的帖子

CAGradient图层在视图中不可见

我尝试在我使用Core Graphics制作的饼图中添加CAGradient效果.事实证明,我无法理解如何将它应用于作为CGPath一部分的视图......

override func draw(_ rect: CGRect)
    {
    ...
    func arc(myRadius: CGFloat, myStartAngle: CGFloat, myEndAngle: CGFloat) {
        // This is the pie chart segment
        context?.setFillColor(phenotypeColor.cgColor)
        context?.move(to: center)
        context?.addArc(center: center, radius: finalRadius, startAngle: myStartAngle, endAngle: myEndAngle, clockwise: true)
        context?.fillPath()

        (...)
        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = self.bounds
        gradientLayer.colors = [UIColor.red, UIColor.blue]
        self.layer.addSublayer(gradientLayer)
    }
Run Code Online (Sandbox Code Playgroud)

我在屏幕上看不到任何渐变(只有白色背景......).最后,clip在保存状态后我也尝试了上下文juste,但我不确定是否剪切了任何东西,因为我没有看到任何渐变(无论是在整个视图上还是仅在片段上).我阅读了文档,但它没有清楚(在我的情况下......).

core-graphics cgcontext ios cagradientlayer swift

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

使用JSON数据参数时NSURLSession崩溃为nil,同时管理错误

这个问题已在其他地方提到,但解决方案是处理错误.在这里,我认为我正确地管理了我的错误(但听起来我错了......).

我有一些奇怪的事情,我无法弄明白.当我检查服务器是否没有响应(离线)而不是通过返回JSON对象时,我的应用程序崩溃了.在我的记忆中,这是在我处理iOS 9.2之前的工作.

使用异常断点,我可以看到它与创建字典时的"nil"数据参数有关(这是正常的,因为服务器处于脱机状态并且没有返回任何内容)但是应该通过管理错误来避免崩溃...在我的代码中似乎不是这种情况.

几行:

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; // url with php script have been set before...

[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[noteDataString dataUsingEncoding:NSUTF8StringEncoding]];

NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *dataRaw, NSURLResponse *response, NSError *error) {
    NSDictionary *json = [NSJSONSerialization
                          JSONObjectWithData:dataRaw
                          options:kNilOptions error:&error];

    // I thought this condition below should manage the error when the json dictionary cannot be set because of the nil "dataRay" paramater but my app crashes.
    if (error) {
        UIAlertView * av = [[UIAlertView alloc] initWithTitle:[NSString …
Run Code Online (Sandbox Code Playgroud)

json nserror ios nsurlsession nsurlsessiondatatask

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

iOS swift imageView无法隐藏在TableViewCell中

我最近在Objective-C项目中添加了一些快速代码,我面临着一些我无法解决的奇怪问题.

我正在使用我定制的Searchbar(来自Ray教程).在cellForRowAtIndexPath方法中,我可以自定义我的单元格标签,一切正常.唯一的问题是我无法根据if(BOOL)条件隐藏一些imageViews.我的swift代码肯定有问题,因为我可以使用相同的if(BOOL)条件在Objective-C文件中隐藏这些图像.

万一我发布我的代码,如果有人可以帮助我.

在SearchVC(快速)

class aCell : UITableViewCell {
    @IBOutlet weak var some label...
    @IBOutlet weak var imageFacturation: UIImageView!
    @IBOutlet weak var imageMail: UIImageView!
}

class PatientSearchViewController : ...

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = self.tableView.dequeueReusableCellWithIdentifier("CellSwift") as aCell // aCell is a class defined inside the file where I attach the label and imageView properties
    var person : ClassObject

    if tableView == self.searchDisplayController!.searchResultsTableView {
        person = filteredObjects[indexPath.row]
    } else {
        person …
Run Code Online (Sandbox Code Playgroud)

hidden uitableview uiimageview ios swift

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