小编Kyl*_*lan的帖子

尝试在UIViewController上呈现UIViewController,其视图不在窗口层次结构中

刚开始使用Xcode 4.5,我在控制台中遇到了这个错误:

警告:尝试在<ViewController:0x1ec3e000>上显示<finishViewController:0x1e56e0a0>,其视图不在窗口层次结构中!

该视图仍在呈现中,应用程序中的所有内容都正常运行.这是iOS 6中的新功能吗?

这是我用来在视图之间切换的代码:

UIStoryboard *storyboard = self.storyboard;
finishViewController *finished = 
[storyboard instantiateViewControllerWithIdentifier:@"finishViewController"];

[self presentViewController:finished animated:NO completion:NULL];
Run Code Online (Sandbox Code Playgroud)

cocoa-touch views hierarchy ios ios6

573
推荐指数
11
解决办法
35万
查看次数

来自swift中字典键的数组

尝试使用swift中字典中的键填充数组.

var componentArray: [String]

let dict = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("Components", ofType: "plist")!)
componentArray = dict.allKeys
Run Code Online (Sandbox Code Playgroud)

这将返回以下错误:'AnyObject'与string不同

也试过了

componentArray = dict.allKeys as String 
Run Code Online (Sandbox Code Playgroud)

但得到:'String'不能转换为[String]

arrays xcode dictionary ios swift

235
推荐指数
9
解决办法
15万
查看次数

如何更改导航栏后退按钮的字体?

如何更改导航栏的后退按钮的字体.

后退按钮是"后退"或前一个视图控制器的标题.

我认为这viewDidLoad会奏效:

navigationController?.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "FONTNAME", size: 20)!], forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)

但是leftBarButton?可选的退货nil.

cocoa-touch uinavigationbar uinavigationcontroller ios swift

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

"用户跟随"与PropelORM - 三种关系

有人能指出我正确的方向做一个"用户跟随"的事情.我有3个表:users,user_follows和posts.

如果我给用户对象加水,我可以得到他们遵循的用户ID数组......并且帖子对象知道哪个用户发布了它......但是很难为给定用户所关注的用户获取帖子.

目前有这个,它返回每个人的帖子.

    $posts = PostsQuery::create()
        ->orderByDate('desc')
        ->limit('12')
        ->find();
    return $posts;
Run Code Online (Sandbox Code Playgroud)

需要做filterByXXX()......

php mysql orm propel

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

CakePHP从数据库查询最近纬度经度

在CakePHP(v3)应用程序中,如何根据传递的lat lng值检索最接近的结果?

我想让它们作为本机CakePHP实体返回,所以像这样:

public function closest($lat, $lng) {

    $sightings = //records within given lat lng 

    $this->set(compact('sightings'));
    $this->set('_serialize', ['sightings']);
}
Run Code Online (Sandbox Code Playgroud)

我知道这个SQL有效:

SELECT *,
       ( 3959 * acos( cos( radians(50.7) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-1.8) ) + sin( radians(50.7) ) * sin( radians( latitude ) ) ) ) AS distance
  FROM sightings
HAVING distance < 10
 ORDER BY distance
 LIMIT 0 , 20
Run Code Online (Sandbox Code Playgroud)

苦苦挣扎将两者结合起来.

UPDATE

我已经添加

class Sighting extends Entity {
    public $_virtual …
Run Code Online (Sandbox Code Playgroud)

php mysql location cakephp cakephp-3.0

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

Xcode调试内存图显示已释放的对象

我一直在寻找一个项目的Xcode Memory Graph工具,并注意到一些奇怪的行为.希望有人能够解释发生了什么/我是否需要担心.

我有一个视图控制器,它创建了几个对象(目前没有做太多)当我解除视图控制器时,它们肯定会被释放.但是在视觉调试器中似乎有一个(有时两个):

在此输入图像描述

只创建了两个,并且两个都被取消了,在我的consol中得到了确认:

在此输入图像描述

我想我是正确的说,我不负责任User何在上图中引用该对象的对象,这是一个错误,还是我不需要担心的事情?

debugging xcode ios swift xcode8

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

在SpriteKit中检测对象的子节点上的触摸

我有一个自定义类,它是一个SKNode,其中包含几个SKSpriteNodes.有没有办法可以从我的游戏场景中检测这些孩子SKSpriteNodes的触摸?

我在迅速工作

xcode touch ios sprite-kit swift

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

自定义 UITableviewCell IBOutlet 始终为零

我有一个自定义 UITableViewCell 子类,其中包含一个用于 UILabel 的简单 IBOutlet 设置。

class SegmentCell: UITableViewCell {

    @IBOutlet weak var test: UILabel!

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        test.text = "Some Text"
    }

    required init?(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
    }

}
Run Code Online (Sandbox Code Playgroud)

确信我已正确设置所有内容并遵循其他答案,但 UILabel 始终为零。

视图控制器:viewDidLoad:

self.tableView.registerClass(SegmentCell.self, forCellReuseIdentifier: "Cell")
Run Code Online (Sandbox Code Playgroud)

cellForForAtIndexPath

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! SegmentCell
    return cell
}
Run Code Online (Sandbox Code Playgroud)
  • 单元格设置为自定义
  • 重用标识符正确
  • Cells 类是 SegmentCell
  • Tableview 内容是动态原型

我错过了什么?

storyboard uitableview ios swift

8
推荐指数
2
解决办法
6089
查看次数

CakePHP 添加事件监听器

我正在努力让 CakePHP (v3.x) 事件中的最终链接正常工作。在我的控制器add方法中我有公共功能

add() 
{
      $event = new Event('Model.Comment.created', $this, [
            'comment' => $comment
      ]);
      $this->eventManager()->dispatch($event);
}
Run Code Online (Sandbox Code Playgroud)

并设置我的监听器类:

namespace App\Event;

use Cake\Log\Log;
use Cake\Event\EventListener;

class CommentListener implements EventListener {

public function implementedEvents() {
    return array(
        'Model.Comment.created' => 'updatePostLog',
    );
}

public function updatePostLog($event, $entity, $options) {
     Log::write(
    'info',
    'A new comment was published with id: ' . $event->data['id']);
}
}
Run Code Online (Sandbox Code Playgroud)

但无法正确设置侦听器,特别是当我的应用程序知道我的CommentListener类存在时。

php cakephp cakephp-3.0

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

CakePHP 3 - 加载用户关注的用户的帖子

尝试加载用户以"Cakey"方式关注的用户的所有帖子.

三张桌子:

用户(id,用户名,密码)

帖子(id,text,user_id,created)

跟随(id,user_id,following_id)

我认为我的关系设置正确,因此我可以加载用户关注者和关注他们的人:

用户表

    $this->belongsToMany('Following', [
        'className' => 'Users',
        'foreignKey' => 'user_id',
        'targetForeignKey' => 'following_id',
        'joinTable' => 'follows'
    ]);

    $this->belongsToMany('Followers', [
        'className' => 'Users',
        'foreignKey' => 'following_id',
        'targetForeignKey' => 'user_id',
        'joinTable' => 'follows'
    ]);
Run Code Online (Sandbox Code Playgroud)

按照表格

    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',
        'joinType' => 'INNER'
    ]);
Run Code Online (Sandbox Code Playgroud)

帖子表

    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',
        'joinType' => 'INNER'
    ]);
Run Code Online (Sandbox Code Playgroud)

现在努力选择单个用户跟随的用户的所有帖子.我认为我需要使用matching()此处记录的方法:通过匹配和联接按关联数据进行过滤,但似乎没有做到正确.

尝试这些方面的东西:

$user_id = $this->Auth->user('id');

$posts = $this->Posts->find()->matching('Users.Following', function ($q)  use ($user_id)  {
      return $q->where(['Users.id' => …
Run Code Online (Sandbox Code Playgroud)

php mysql database cakephp cakephp-3.0

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

现在的社会视图控制器Cocos2d

我试图使用社交框架从Cocos2d内呈现"Post To Facebook"视图控制器.这是我通常在故事板应用程序中使用的代码

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
    facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [facebook setInitialText:[NSString stringWithFormat:@"text"]];
    [self presentViewController:facebook animated:YES completion:nil];
    [facebook setCompletionHandler:^(SLComposeViewControllerResult result) {
        NSString *output;
        switch (result) {
            case SLComposeViewControllerResultCancelled:
                output = @"Action Cancelled";
                break;
            case SLComposeViewControllerResultDone:
                output = @"Posted";
                NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
                [ud setInteger:1 forKey:@"Shared"];
                [ud synchronize];
            default:
                break;
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alert show];
    }];
}
Run Code Online (Sandbox Code Playgroud)

我如何在Cocos2d中启动并运行它?目前它引发了对该线的警告

[self presentViewController:facebook animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

提前致谢

social facebook uiviewcontroller cocos2d-iphone

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