小编Ram*_*sel的帖子

CocoaPods和GitHub分叉

这是我第一次分支GitHub项目,我对CocoaPods也不太称职,所以请耐心等待.

基本上,我在我的GitHub中使用以下代码分叉了一个项目Podfile:

pod 'REActivityViewController', '~> 1.6.7', :git => 'https://github.com/<username>/REActivityViewController.git'
Run Code Online (Sandbox Code Playgroud)

然后我对fork进行了一些更改,当然,当我pod install安装另一个pod时,它重新安装了原始版本REActivityViewController并删除了我的更改.

我意识到我需要在另一个之前将我的更改推送到我的fork pod install,但是我如何做到这一点,这是由CocoaPods安装的repo?我查看了REActivityViewController文件夹下安装的Pods文件夹,没有任何git文件.

我是否需要在项目之外的fork上工作,然后使用CocoaPods来安装更改?这对工作流来说太麻烦了.

或者我是否需要对子模块执行某些操作?

github cocoapods git-fork

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

在UILabel.attributedText中建立链接*不是*蓝色,*不是*带下划线

我希望我的OHAttributedLabel中的一些单词是链接,但我希望它们是蓝色以外的颜色,我不想要下划线.

这给了我一个带下划线文字的蓝色链接:

 -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{

    NSMutableAttributedString* mutableAttributedText = [self.label.attributedText mutableCopy];   

    [mutableAttributedText beginEditing];
    [mutableAttributedText addAttribute:kOHLinkAttributeName
                   value:[NSURL URLWithString:@"http://www.somewhere.net"]
                   range:range];

    [mutableAttributedText addAttribute:(id)kCTForegroundColorAttributeName
                   value:color
                   range:range];

    [mutableAttributedText addAttribute:(id)kCTUnderlineStyleAttributeName
                   value:[NSNumber numberWithInt:kCTUnderlineStyleNone]
                   range:range];
    [mutableAttributedText endEditing];


    self.label.attributedText = mutableAttributedText;

}
Run Code Online (Sandbox Code Playgroud)

由于我正在使用OHAttributedLabel,我也尝试使用它的NSAttributedString+Attributes.h类别中的方法,但那些返回蓝色下划线链接:

-(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{

NSMutableAttributedString* mutableAttributedText = [self.label.attributedText mutableCopy];

[mutableAttributedText setLink:[NSURL URLWithString:@"http://www.somewhere.net"] range:range];
[mutableAttributedText setTextColor:color range:range];
[mutableAttributedText setTextUnderlineStyle:kCTUnderlineStyleNone range:range];

self.label.attributedText = mutableAttributedText;
}
Run Code Online (Sandbox Code Playgroud)

如果我注释掉在每个版本中设置链接的行,那么文本就会变成我传入的内容 - 这是有效的.似乎设置链接覆盖了这个并将其转回蓝色.

不幸的是,我发现的apple docs页面显示了如何将链接文本设置为蓝色并加下划线,正是我不需要的:https: //developer.apple.com/library/content/documentation/Cocoa/Conceptual/AttributedStrings/任务/ ChangingAttrStrings.html

xcode objective-c nsattributedstring ios

37
推荐指数
6
解决办法
3万
查看次数

以编程方式单击按钮 - JS

我已经在其他网络应用程序中看到过这种情况,但我对Javascript还不熟悉,并且无法自己解决这个问题.我想以编程方式创建Google Hangout.但是,在官方API中,您可以创建环聊的唯一方法是在页面上添加环聊按钮.

这是环聊按钮上的Google文档.

我想要做的是让用户点击另一个用户的img并以这种方式打开环聊.似乎我可以捕获该点击,然后在后台"点击"环聊按钮.但是,我对Javascript不是很好,所以我不知道如何实现这一点.

编辑

我在下面尝试了mohamedrais的解决方案但没有运气.它与按钮的类有关吗?

以下是该按钮的代码,取自环聊文档并添加了id:

 <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script>
        <div class="g-hangout" id="hangout-giLkojRpuK"
                                data-render="createhangout">
        </div>
Run Code Online (Sandbox Code Playgroud)

这是我添加的JS,用ids 渲染:

     <script>
          window.onload = function() {

              var userImage = document.getElementById("img-giLkojRpuK");
              var hangoutButton = document.getElementById("hangout-giLkojRpuK");

              userImage.onclick = function() {

                console.log("in onclick");
                hangoutButton.click(); // this will trigger the click event
              };
          };
        </script>
Run Code Online (Sandbox Code Playgroud)

当我单击时img,"on onclick"被记录,因此函数被调用.但是,没有任何反应 - 环聊未启动.

当我直接点击环聊按钮时,它会启动环聊.但是,我想最终隐藏它并从图像中执行单击.

以下是上方环聊按钮的图片img:

在此输入图像描述

javascript

26
推荐指数
3
解决办法
10万
查看次数

UITableViewCell setSelected:animated:not working

这真让我抓狂.我在这里看过SO,因为我认为这是一个简单的答案,但找不到一个.

在我的自定义中UITableViewCell:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{   
    // Configure the view for the selected state
    if (selected) {        
        [self.languageLevelNameLabel setTextColor:[UIColor blackColor]];        
    }
    else {        
        [self.languageLevelNameLabel setTextColor:[UIColor colorMessageCountZero]];
    }

    [self setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

tableView:cellForRowAtIndexPath:控制器中:

 if ([level integerValue] == indexPath.row) {

        [cell setSelected:YES];
    }
Run Code Online (Sandbox Code Playgroud)

我已插入断点并selected == YES正在传递正确的单元格,并且if语句正在执行时应该是,但文本永远不会被设置为blackColor.

cocoa-touch objective-c uitableview

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

如何抓取/索引经常更新的网页的策略?

我正在尝试构建一个非常小的小众搜索引擎,使用Nutch来抓取特定网站.一些网站是新闻/博客网站.如果我抓取,例如techcrunch.com,并存储和索引他们的首页或任何主要页面,那么在几小时内,我的该页面的索引就会过时.

像Google这样的大型搜索引擎是否有一种算法可以非常频繁地每小时重新抓取经常更新的页面?或者它只是经常更新的页面得分非常低,所以他们不会被退回?

我如何在自己的应用程序中处理这个问题?

search-engine web-crawler

17
推荐指数
3
解决办法
3941
查看次数

Heroku上的HTTPS + SSL - Node + Express

我已经创建了一个自签名证书,将其添加到Heroku,并在Heroku上配置了一个SSL端点,我记录heroku certs:info它似乎就在那里.

我正在Express上创建我的服务器,如下所示:

var server = require('http').createServer(app);
Run Code Online (Sandbox Code Playgroud)

然后重定向到https这样:

app.use(function(req, res, next) {
    var reqType = req.headers["x-forwarded-proto"];
    reqType == 'https' ? next() : res.redirect("https://" + req.headers.host + req.url);
});
Run Code Online (Sandbox Code Playgroud)

服务器运行正常,但我在SO上遇到了这个代码片段来创建一个https服务器:

var keys_dir = './sslcert/';
var server_options = { 
  key  : fs.readFileSync(keys_dir + 'server.key'),
  ca   : fs.readFileSync(keys_dir + 'server.csr'), 
  cert : fs.readFileSync(keys_dir + 'server.crt') 
}

var server = require('https').createServer(server_options,app);
Run Code Online (Sandbox Code Playgroud)

我没有像这个例子那样指向certs/keys,我的网站在https上运行(尽管锁是红色的,因为它是自签名的).

  • 所以我的问题是,我的服务器如何知道我的密钥/证书,而没有我像代码片段那样明确地指向他们server_options?这是Heroku在幕后照顾的吗?

  • 我在Heroku上设置的SSL端点如何与http我创建的服务器交互var server = require('http').createServer(app);


编辑 …

ssl https heroku node.js

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

如何设置RedisStore - Node,Express,Socket.io,Heroku

我正在使用部署在Heroku上的Node和Express 4.0,我正在尝试使用Redis实现Socket.io作为会话存储.所以我将此作为我当前的代码:

 var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var RedisStore = io.RedisStore;

if (process.env.REDISTOGO_URL) {
    // inside if statement
    var rtg   = require("url").parse(process.env.REDISTOGO_URL);
    var redis = require("redis").createClient(rtg.port, rtg.hostname);

    redis.auth(rtg.auth.split(":")[1]);
} else {
    var redis = require("redis").createClient();
}

/** Initialize RedisStore for socket.io **/
io.set('store', new RedisStore({
  redis    : redis
}));
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

14:25:03 web.1  | io.set('store', new RedisStore({
14:25:03 web.1  |                 ^
14:25:03 web.1  | TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)

我也看过这种定义RedisStore的方法:

var redis = …
Run Code Online (Sandbox Code Playgroud)

heroku node.js express socket.io

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

用户评级的模式 - 密钥/值DB

我们正在使用MongoDB,我正在计算用于存储评级的模式.

  • 评级的值为1-5.
  • 我想存储其他值,如 fromUser

这很好,但我的主要问题是设置它,以便重新计算平均值尽可能高效.


解决方案1 ​​ - 单独的评级等级

首先想到的是,创建一个单独的Ratings类和指针数组存储RatingsUser类.我第二次猜到这一点的原因是,Ratings每次新的Rating进入时我们都必须查询所有对象,以便我们可以重新计算平均值

...

解决方案2 - 用户类中的字典

第二个想法是User直接在类中存储一个字典来存储这些Ratings对象.这比解决方案1稍微轻一点,但我们Ratings每次更新时都会重写每个用户的整个历史记录.这似乎很危险.

...

解决方案3 - 用户类别中具有单独平均值的单独评级类别

混合选项,我们Ratings在他们自己的类中,以及它们的指针数组,但是,我们在用户类中保留两个值 - ratingsAveratingsCount.这样,当设置新的评级时,我们保存该对象,但我们可以ratingsAve轻松地重新计算.


解决方案3听起来对我来说最好,但我只是想知道我们是否需要通过重新检查评级历史记录来重新定义ratingsAve以确保所有内容都检出来定期校准.

我可能会过度思考这个但是我在数据库模式创建方面并不是那么出色,这看起来像是一个标准的模式问题,我应该知道如何实现.

哪个是确保一致性以及重新计算效率的最佳选择?

mongodb database-schema

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

Cocoapods和forked repo问题

所以这是我的podfile:

workspace 'WSPhoto.xcworkspace'
platform :ios, :deployment_target => "6.1"

xcodeproj 'WSPhoto'

pod 'Parse-iOS-SDK', '~> 1.2.17'
pod 'REActivityViewController',  :git => 'https://github.com/ramsel/REActivityViewController.git', :commit => 'f027011e8159393cf678d7c67c408891b609a6ef'
pod 'SWTableViewCell', :git => 'https://github.com/ramsel/SWTableViewCell.git', :commit => '6f4e55e554c1b26ff3c850eb331273b536e4f900'
pod 'ELCImagePickerController', '~> 0.2.0'
pod 'ChimpKit'
Run Code Online (Sandbox Code Playgroud)

我正在根据前一个问题中的建议分配一些repos并将Cocoapods指向我的forks的特定提交:

CocoaPods和GitHub分叉

但是,我收到以下错误pod install --verbose:

Fetching external sources
-> Pre-downloading: `REActivityViewController` from `https://github.com/ramsel/REActivityViewController.git`, commit `f027011e8159393cf678d7c67c408891b609a6ef`
 > GitHub download
   $ /usr/bin/git config core.bare
   true
   $ /usr/bin/git config core.bare
   true
   $ /usr/bin/git rev-list --max-count=1
   f027011e8159393cf678d7c67c408891b609a6ef
   fatal: bad object f027011e8159393cf678d7c67c408891b609a6ef
   [!] Failed: /usr/bin/git rev-list --max-count=1 …
Run Code Online (Sandbox Code Playgroud)

github cocoapods git-fork

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

合并字典 - 不兼容的类型错误

我一直试图将两个NSDictionaries合并几个小时.搜索并发现我可以使用[NSMutableDictionary addEntriesFromDictionary:].

    NSDictionary *areaAttributes = [[area entity] attributesByName];
    NSDictionary *gpsAttributes = [[gps entity] attributesByName];

    NSMutableDictionary *areaAttributesM = [areaAttributes mutableCopy];
    NSMutableDictionary *gpsAttributesM = [gpsAttributes mutableCopy];

    NSMutableDictionary *combinedAttributes =  [areaAttributesM addEntriesFromDictionary:gpsAttributesM];
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

Initializing 'NSMutableDictionary *_strong' with an expression of incompatible type 'void'
Run Code Online (Sandbox Code Playgroud)

所以这就是[areaAttributesM addEntriesFromDictionary:gpsAttributesM]回报void?我的理解是否正确?为什么它回归无效?

objective-c nsdictionary ios

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