小编i_a*_*orf的帖子

用c ++旋转一个字符串?

我正在寻找一种在c ++中旋转字符串的方法.我把所有的时间花在python上,所以我的c ++ 非常生疏.

这就是我想要它做的事情:如果我有一个字符串'abcde',我希望它改为'bcdea'(第一个字符移到结尾).这是我在python中做到的方式:

def rotate(s):
    return s[1:] + s[:1]
Run Code Online (Sandbox Code Playgroud)

我不知道如何在cpp中做到这一点.也许使用一系列字符?

c++ string

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

我是否需要释放返回的NSError对象?

有许多Cocoa方法需要NSError对象作为方法的参数,但实际上是一种在出现错误时将错误对象返回给调用方法的方法.这个返回的对象是否保留?也就是说,在调用对象代码(返回错误的方法)中,是否需要一些代码,如:

  NSError *error;
  [apiCall .... error:&error];

  if (error){
    [*error release];
 }
Run Code Online (Sandbox Code Playgroud)

我没有在任何地方看到这个,如果确实需要发布,这是这样做的方法吗?

iphone error-handling cocoa memory-management objective-c

7
推荐指数
2
解决办法
3241
查看次数

未调用UITableView cellforrowatindexpath

我是Iphone开发的新手.如果我问一些非常简单的问题,请耐心等待.

在我的应用程序中,我有多个视图(即.xib文件).上点击主视图中的按钮(CouponWebsiteViewController.Xib)应用程序应该加载含有UITable所述第二视图(BrowseList.Xib),我有来填充UITable与一些数据.我编写了以下代码来填充BrowseList.m文件中的数据:

- (void) viewDidLoad{
    arrayData = [[NSArray alloc] init];
    arrayData = [arrayData arrayByAddingObject:@"dfsgdf"];
    arrayData = [arrayData arrayByAddingObject:@"aaaaaa"];
    self.lblNewScreen.text = [arrayData objectAtIndex:0];
    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arrayData count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) …
Run Code Online (Sandbox Code Playgroud)

uitableview

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

获取HTML元素相对于Window的边界框的正确方法是什么?

我正在写一个Firefox扩展.我试图将它限制为只有XUL + Javascript(没有XPCOM).当我得到一个mouseoverHTML元素的事件时,我需要在windows坐标系中获取它的边界框(即内置的XUL文档browser.xul).

显而易见的地方是在mouseover事件处理程序中放置这样的东西:

var rect = e.target.getBoundingClientRect();
Run Code Online (Sandbox Code Playgroud)

这很棒,但是它给了我HTML文档坐标系中的矩形,它相对于HTML绘图区域的左上角.我想在这个图像附近使用panel.openPopup()显示一个xul:panel元素(但不使用其中一个预定义的弹出位置),所以我需要翻译坐标.

我尝试过以下(在XUL dom中)来获取偏移量来进行翻译,它适用于某些网站,但不是全部,并且似乎没有考虑到侧边栏所需的x翻译.

var appcontent = document.getElementById("appcontent");
if (appcontent) {
  chromeOffsetX = r.left;
  chromeOffsetY = r.top;
}
Run Code Online (Sandbox Code Playgroud)

那么,最好的方法是什么?

注意:对于IE扩展,我会使用(并使用过)IDisplayServices :: TransformRect() - 对于Firefox有类似的东西吗?

现在有赏金!

javascript xul firefox-addon bounding-box

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

使用onResume方法重新启动Activity

我想用onResume()方法重新启动一个活动.我以为我可以使用Intent来实现它,但这会以无限循环结束.

@Override
protected void onResume() {
    Intent intent = new Intent(MainActivity.this, MainActivity.class);
    MainActivity.this.startActivity(intent);
    finish();
    super.onResume();
}
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以重新启动活动?

android android-activity

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

初始化3D矢量的最有效方法是什么?

我在C++中有一个3D字符串向量:

vector<vector<vector<string>>> some_vector
Run Code Online (Sandbox Code Playgroud)

我正在尝试的是找到一种快速的方法来为它分配内存.

我试着用两种不同的方法来定义它,如下所示:

#include<vector>
#include<iostream>
#include<ctime>
using namespace std;

#define DIM1 100
#define DIM2 9
#define DIM3 120

int main()
{
    clock_t t1_start = clock();
    vector<vector<vector<string>>> vec1(DIM1, vector<vector<string>>(DIM2, vector<string>(DIM3)));
    clock_t t1_end = clock();
    double diff1 = (t1_end - t1_start) / double(CLOCKS_PER_SEC);

    clock_t t2_start = clock();
    vector<vector<vector<string>>> vec2;
    vec2.resize(DIM1);
    for(int i = 0; i < DIM1; i++)
    {
        vec2[i].resize(DIM2);
        for(int j = 0; j < DIM2; j++)
            vec2[i][j].resize(DIM3);
    }
    clock_t t2_end = clock();

    double diff2 = (t2_end - t2_start) …
Run Code Online (Sandbox Code Playgroud)

c++ performance vector

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

UICollectionViewCell的alpha属性在重新加载后才会生效?

如果我cellForItemAtIndexPath按如下方式设置单元格的alpha属性...

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("CGPathCell", forIndexPath: indexPath) as UICollectionViewCell
// Prepare cell
cell.alpha = 0.5
cell.setNeedsDisplay()
return cell
}
Run Code Online (Sandbox Code Playgroud)

...最初出现的细胞是不透明的(α为1.0).如果我滚动,出现的"新"(重用)单元格具有预期的alpha值.如果我滚动回到开头,"原始"单元格(开始不透明)现在也具有预期的alpha值.

为什么在初始加载时未设置alpha值?

其他不起作用的尝试:

  1. 将此添加到委托,我得到相同的结果:

    func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
        cell.alpha = 0.5
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将此添加到cellForItemAtIndexPath:

    let attrs = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
    attrs.alpha = 0.5
    cell.applyLayoutAttributes(attrs)
    
    Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewcell swift

7
推荐指数
2
解决办法
1877
查看次数

如何将NSAttributedString保存到CoreData

我想保存我的UItextview'text的attributedString.我试图转换为字符串并保存.但是当我回到设置text'attributedString时,它不起作用.

这是我转换为String的方式:

var a = String(stringInterpolationSegment: text.attributedText)
    Data.setValue(a, forKey: "font")
    Data.managedObjectContext?.save(nil)
Run Code Online (Sandbox Code Playgroud)

这是我回到设置的方式:

text.attributedText = NSAttributedString(string: size)
Run Code Online (Sandbox Code Playgroud)

但是我的TextView只显示了AttributedSting

{
NSFont = "<UICTFont: 0x7fa9fa82aec0> font-family: \"Helvetica Neue\"; font-weight: normal; font-style: normal; font-size: 18.00pt";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel …
Run Code Online (Sandbox Code Playgroud)

core-data uitextview nsattributedstring ios swift

7
推荐指数
2
解决办法
3298
查看次数

多个让一个保护语句与单个let一样吗?

以下是否有任何功能差异:

guard let foo = bar, let qux = taco else { 
  ...
}
Run Code Online (Sandbox Code Playgroud)

和:

guard let foo = bar, qux = taco else {
  ...
}
Run Code Online (Sandbox Code Playgroud)

在我看来他们是一样的,额外let的不是必需的?

guard swift swift3

7
推荐指数
2
解决办法
4281
查看次数

Pod安装失败,私有pod从私有repo作为二进制文件提供

我有一个私人吊舱和一个私人规格仓库.我作为二进制文件提供pod,即podspec说:

s.source = { 
  :http => 'https://github.com/COMPANY/PROJECT/releases/download/v1.0/PrivatePod.zip' 
}
Run Code Online (Sandbox Code Playgroud)

我的Podfile具有以下源信息:

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/COMPANY/Specs.git'
Run Code Online (Sandbox Code Playgroud)

当我运行pod installgit提示输入密码来克隆我的私有spec repo时,这很棒.

但是,pod install尝试使用curl没有身份验证的二进制zip包,因此GitHub返回404:

Installing PROJECT 1.0 (was 1.0)

[!] Error installing PROJECT [!] /usr/bin/curl -f -L -o /var/folders/_g/52mwshws60v8622n81hv7h7w0000gn/T/d20170608-80045-1l3flqz/file.zip https://github.com/COMPANY/PROJECT/releases/download/v1.1/PrivatePod.zip --create-dirs --netrc-optional
...
curl: (22) The requested URL returned error: 404 Not Found
Run Code Online (Sandbox Code Playgroud)

我不想公开二进制文件.有没有办法告诉CocoaPods在这里做一些认证?

我尝试将凭证放入.netrc其中,CocoaPods似乎很乐意使用,但GitHub仍然无法使用404的请求,即使我看到curl现在正在使用基本身份验证.如果我使用netrc for auth使用curl发出API请求,我会得到很好的响应.但我无法下载发布资产.

我可以使用.netrc从api端点获取发布资产,但只有在我指定时-H 'Accept: application/octet-stream',我才知道如何让CocoaPods这样做.

github cocoapods podspec podfile

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