小编OMG*_*POP的帖子

iOS:如何在不在故事板中实际拥有单元格的情况下将可重复使用的"默认"单元格出列

我有几个表默认单元格,例如带标题的单元格,或左侧带图标的单元格和右侧标题.

我不想在故事板中添加这些单元格并为其分配标识符,是否可以这样做?

它必须是可重用的,我知道如何分配新的不可重用的单元格

我试过下面的答案,

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MyCellIdentifier];
Run Code Online (Sandbox Code Playgroud)

应该是正确的,但这是非常乏味的,很容易忘记

UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
   cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Run Code Online (Sandbox Code Playgroud)

以上可能更好,因为它将所有代码放在一个地方,但是当我尝试dequeueReusableCellWithIdentifier:forIndexPath :(使用indexPath)时它会崩溃.

  1. 为什么dequeueReusableCellWithIdentifier:forIndexPath崩溃而dequeueReusableCellWithIdentifier没有?
  2. 如果我没有传入indexPath,那么该单元是否可重用
  3. 如果它是可重用的,那么使用dequeueReusableCellWithIdentifier:forIndexPath?

cocoa-touch uitableview uikit ios

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

Android如何将iOS中的异步任务组合在一起

我在iOS应用程序中有一个功能,用于dispatch_group对多个休息请求进行分组:

static func fetchCommentsAndTheirReplies(articleId: String, failure: ((NSError)->Void)?, success: (comments: [[String: AnyObject]], replies: [[[String: AnyObject]]], userIds: Set<String>)->Void) {
    var retComments = [[String: AnyObject]]()
    var retReplies = [[[String: AnyObject]]]()
    var retUserIds = Set<String>()

    let queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
    Alamofire.request(.GET, API.baseUrl + API.article.listCreateComment, parameters: [API.article.articleId: articleId]).responseJSON {
        response in

        dispatch_async(queue) {

            guard let comments = response.result.value as? [[String: AnyObject]] else {
                failure?(Helper.error())
                return
            }
            print(comments)
            retComments = comments

            let group = dispatch_group_create()

            for (commentIndex, comment) in comments.enumerate() {
                guard let id …
Run Code Online (Sandbox Code Playgroud)

java android ios android-asynctask swift

27
推荐指数
3
解决办法
3761
查看次数

预存和验证之间的猫鼬差异?什么时候使用哪一个?

目前我正在使用pre('save')验证:

UserSchema.pre('save', true, function(next, done) {
    var self = this //in case inside a callback
    var msg = helper.validation.user.username(self.username)
    if (msg) {
        self.invalidate('username', msg)
        done(helper.getValidationError(msg))
    }
    else
        done()
    next()
})
Run Code Online (Sandbox Code Playgroud)

辅助模块有一个接受输入并返回错误消息的函数.

exports.user = {
    username: function(input) {
        if (!input)
            return 'username is required'
        var min = 3
        var max = 10
        if (input.length < min)
            return 'username min of length is ' + min
        if (input.length > max)
            return 'username max of length is ' + max
        return …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js express

18
推荐指数
2
解决办法
5617
查看次数

iOS 7核心图像QR码生成过于模糊

这是我生成QRCode图像的代码

+ (UIImage *)generateQRCodeWithString:(NSString *)string {
    NSData *stringData = [string dataUsingEncoding:NSUTF8StringEncoding];
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    [filter setValue:stringData forKey:@"inputMessage"];
    [filter setValue:@"M" forKey:@"inputCorrectionLevel"];
    return [UIImage imageWithCIImage:filter.outputImage];
}
Run Code Online (Sandbox Code Playgroud)

结果太模糊了.是否可以设置生成的qr代码的大小?

core-image uikit ios

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

Angular资源如何保持ajax头并同时启用cors

在我的ng-resource文件中,我启用了ajax标头:

var app = angular.module('custom_resource', ['ngResource'])

app.config(['$httpProvider', function($httpProvider) {
    //enable XMLHttpRequest, to indicate it's ajax request
    //Note: this disables CORS
    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}])

app.factory('Article', ['$resource', function($resource) {
    return $resource('/article/api/:articleId', {articleId: '@_id'}, {
        update: {method: 'PUT'},
        query: {method: 'GET', isArray: true}
    })
}])
Run Code Online (Sandbox Code Playgroud)

这样我就可以相应地分离ajax和非ajax请求和响应(发送json数据res.json(data),或者像发送整个html页面一样res.render('a.html')

例如,在我的错误处理程序中,我需要决定呈现error.html页面或只发送错误消息:

exports.finalHandler = function(err, req, res, next) {
    res.status(err.status || 500)
    var errorMessage = helper.isProduction() ? '' : (err.message || 'unknown error')

    if (req.xhr) {
        res.json({message: errorMessage})
    }
    else {
        res.render(dir.error + '/error_page.ejs') …
Run Code Online (Sandbox Code Playgroud)

ajax xmlhttprequest node.js express angularjs

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

不使用java中的条件语句检查正面或负面

我上周被问到一个面试问题:

我需要一个函数来打印数字是正数还是负数而不使用条件语句等if else while for switch a? b:c.我该怎么做.

我告诉采访者,这个问题本质上是"有条件的",这是不可能的.他告诉我这是可能的,但没告诉我怎么做.我做了很多搜索,但没有很好的答案.

java

11
推荐指数
3
解决办法
6829
查看次数

ios刮刮卡效果崩溃

我需要为我的游戏使用划痕效果.这是几年前的示例代码.

https://github.com/oyiptong/CGScratch

它工作正常,但当我与导航控制器一起使用时,它会崩溃.

我的项目使用ARC,我将文件标记为-fno-objc-arc.这是源代码:

https://github.com/lifesaglitch/ScratchWithError

当我按下视图控制器,然后弹出,然后重新进入时崩溃.

编辑:

当您将all转换为arc,并将使用临时视图的视图控制器标记为-fno-objc-arc时,它可以正常工作.但是当您将临时视图标记为-fno-objc-arc时,它会再次崩溃.我的项目使用arc,我不认为我可以将自己的视图控制器转换为-fno-objc-arc.

编辑2:

我将初始化代码修改为:

    scratchable = CGImageRetain([UIImage imageNamed:@"scratchable.jpg"].CGImage);
Run Code Online (Sandbox Code Playgroud)

它不再崩溃,但是有内存泄漏.并且在dealloc方法中调用CGImageRelease一次.

iphone core-graphics ios

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

触摸时Uibutton触摸向下操作未调用,但触摸移动时调用

当用户触摸DOWN UIButton时,您需要执行操作

[button addTarget:self action:@selector(touchDown:event:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(drag:event:) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:self action:@selector(drag:event:) forControlEvents:UIControlEventTouchDragOutside];
[button addTarget:self action:@selector(touchUp:event:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(touchUp:event:) forControlEvents:UIControlEventTouchUpOutside];

- (void)touchDown:(UIButton *)sender event:(UIEvent *)event {
    //begin only called when I move my finger 
}


- (void)drag:(UIButton *)sender event:(UIEvent *)event {
    //called when I move my finger, after touchDown was called
}
- (void)touchUp:(UIButton *)sender event:(UIEvent *)event {

}
Run Code Online (Sandbox Code Playgroud)

我的应用程序的根视图控制器是tabbarviewcontroller,每个选项卡都是导航视图控制器.在聊天场景的viewWillAppear方法中,我隐藏了标签栏.

结果是,在设备上,当我触摸时,它没有被调用,当我移动我的手指时,它被调用.

注意:

  1. 使用长按手势识别器也不起作用.

  2. 如果我将按钮远离标签栏区域,它可以在设备上运行.

  3. 在模拟器上,一切都很好.

我创建了一个示例项目:https: //drive.google.com/folderview?id = 0B_9_90avvmZtRmRDeHFkbFJLaFk&usp =sharing

cocoa-touch objective-c uikit ios

8
推荐指数
3
解决办法
7245
查看次数

黄瓜未定义的步骤,虽然使用IntelliJ定义

我正在尝试运行.feature文件来测试一个简单的RESTEasy Web应用程序:https://github.com/dashorst/jaxrs-quickstart-resteasy.

然而,IntelliJ一直说:

Undefined step: Given  I am an invalid username

Undefined step: When  I perform a hello request with null username

Undefined step: Then  I receive a http response code of 400

Undefined step: When  I perform a hello request with empty username

Undefined step: Then  I receive a http response code of 400

You can implement missing steps with the snippets below:

@Given("^I am an invalid username$")
public void I_am_an_invalid_username() throws Throwable {
    // …
Run Code Online (Sandbox Code Playgroud)

java intellij-idea cucumber

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

cocos2d-x如何将plist读入数组

我想用cocos2d-x(c ++)读一个plist这里是我的plist:

<array>
    <dict>
        <key>x</key>
        <integer>0</integer>
        <key>y</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>x</key>
        <integer>140</integer>
        <key>y</key>
        <integer>12</integer>
    </dict>
    <dict>
        <key>x</key>
        <integer>120</integer>
        <key>y</key>
        <integer>280</integer>
    </dict>
    <dict>
        <key>x</key>
        <integer>40</integer>
        <key>y</key>
        <integer>364</integer>
    </dict>
<array>
Run Code Online (Sandbox Code Playgroud)

它基本上是由(x,y)坐标组成的字典数组.我原来的阅读代码是:

NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"w%i", world] ofType:@"plist"];
NSMutableArray* points = [NSMutableArray arrayWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)

但现在我需要将其翻译成c ++中的cocos2d-x.我用Google搜索了一些文章,但它们都是关于将plist读入字典.我需要一个阵列.

编辑:::

现在我改变了我的plist格式:

<dict>
    <key>11x</key>
    <integer>0</integer>
    <key>11y</key>
    <integer>0</integer>
    <key>12x</key>
    <integer>140</integer>
    <key>12y</key>
    <integer>12</integer>
<dict>
Run Code Online (Sandbox Code Playgroud)

我该怎么办???我仍然得到同样的错误:

CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFile(plistPath);
int x = (int)dict->objectForKey("11x");
int y = (int)dict->objectForKey("11y");
Run Code Online (Sandbox Code Playgroud)

不行.请先试一试.看看你是否可以从样本plist中读取一个int

iphone plist cocos2d-iphone ios cocos2d-x

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