小编cri*_*ald的帖子

Web Api Request.CreateResponse HttpResponseMessage no intellisense VS2012

出于某种原因,Request.CreateResponse在VS2012中现在是"红色",当我将鼠标悬停在IDE的使用状态时

无法解析符号'CreateResponse'

这是ApiController类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Filters;
using GOCApi.Attributes;
using GOCApi.Models;
using GOCApi.Models.Abstract;
using AttributeRouting;
using AttributeRouting.Web.Http;

namespace GOCApi.Controllers
{
    [RoutePrefix("Courses")]
    public class CoursesController : ApiController
    {
        private ICoursesRepository _coursesRepository { get; set; }

        public CoursesController(ICoursesRepository coursesRepository)
        {
            _coursesRepository = coursesRepository;
        }

        [GET("{id}")]
        public HttpResponseMessage Get(int id)
        {
            var course = _coursesRepository.GetSingle(id);
            if (course == null)
            return Request.CreateResponse(HttpStatusCode.NotFound, "Invalid ID");
            return Request.CreateResponse(HttpStatusCode.OK, course);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,代码确实可以编译和工作,只是看到屏幕上的所有"红色"真的很烦人.此外,当我输入时,intellisense现在不起作用Request.CreateResponse …

c# asp.net-mvc-4 asp.net-web-api visual-studio-2012

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

检查getter中的CGRect是否为null

我试图检查a CGRect是否null在我的属性getter中,如果是,默认情况下加载一个值,但是,在我的init方法中,当我使用该属性时,它为所有值返回零.

这是我的吸气鬼:

- (CGRect)frame
{
    if(CGRectIsNull(_frame))
        _frame = CGRectMake(0,0,60,60);
    return _frame;
}

- (id)init
{
    self = [super initWithFrame:self.frame];
    if(self)
    {
        //do something
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

我不确定发生了什么,在哪里看.任何帮助深表感谢.

null ios cgrect cgrectmake ios6

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

iOS 6 UITextField Secure - 如何检测退格清除所有字符?

在iOS 6中,如果您在安全文本字段中键入文本,请更改为另一个文本字段,然后返回到安全文本字段并点击退格键,将删除所有字符.我对这种情况很好,但是,我试图根据此安全文本字段是否包含字符来启用/禁用按钮.我知道如何确定字段中的字符是什么,以及是否有命中退格但是我无法确定如何检测是否正在清除所有字符.

这是我用来获取字段的新文本的委托方法,但是,如果退格是,我似乎无法弄清楚如何获取新文本(假设新文本只是一个空白字符串)点击清除所有角色.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    //returns the "new text" of the field
    NSString * text = [textField.text stringByReplacingCharactersInRange:range withString:string];
}
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢.

谢谢!

cocoa-touch uitextfield uitextfielddelegate ios6

15
推荐指数
2
解决办法
7036
查看次数

带有大标题导航的 UITableView UIRefreshControl 不会粘在顶部 - 它会移动

我使用了带有大标题的 UITableView.refreshControl。我试图模仿本机邮件应用程序使用拉动刷新的方式。对我来说,刷新控件会移动并且不会像邮件应用程序那样停留在屏幕顶部。这是一个游乐场:

//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class ViewController: UIViewController {
    public init() {
        super.init(nibName: nil, bundle: nil)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var refresh: UIRefreshControl = {
        let refreshControl = UIRefreshControl()
        refreshControl.backgroundColor = .clear
        refreshControl.tintColor = .black
        refreshControl.addTarget(self, action: #selector(refreshIt), for: .valueChanged)
        return refreshControl
    }()
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.refreshControl = refresh
        tableView.delegate …
Run Code Online (Sandbox Code Playgroud)

xcode uitableview ios uirefreshcontrol swift

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

将项目添加到image.onload()的数组时,Angular 2 UI不更新

我正在尝试将图像添加到阵列并将其显示在屏幕上。在浏览器加载图像之前,我不希望显示它们。我在图像对象上指定了.onload回调,并将图像添加到该回调中的数组中。仅在发生点击事件或其他“更改事件”时才更新UI。我看了看可观察的东西,但是觉得这对于一些简单的东西来说有点过大了。我相信在angular 1中可以使用某种$ watch来对属性进行分类。这似乎微不足道...对象已更新,UI应该反映出来。任何帮助表示赞赏。谢谢 :)

这里是一个plunker示范什么,我试图做的。我在构造函数中添加了X只小猫。如果删除了该代码,则第一次按“添加小猫”的操作不会更新用户界面,但随后添加的小猫会显示以前的小猫...

private addItem(itemsArray) { 
    var randomnumber = Math.floor(Math.random() * (500 - 200 + 1)) + 200;  
    var imageObj = new Image();
    imageObj.src = "http://placekitten.com/300/"+randomnumber;

    imageObj.onload = function () {       
        itemsArray.push(imageObj);
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous typescript plunker angular

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

iOS 7如何将StatusBarStyle从DefaultContent设置为LightContent

我正在尝试使用UIView动画将状态栏样式从UIStatusBarStyleDefaultContent转换UIStatusBarStyleLightContent,但是,样式只是在没有淡入淡出动画的情况下切换.我认为使用以下方式设置样式会起作用:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
                     [self.view layoutIfNeeded];
                 } completion:nil];
Run Code Online (Sandbox Code Playgroud)

我不知道如何得到我想要发生的事情.基本上,我的内容从黑暗变为浅,所以我需要更改状态栏颜色.默认情况下,它不能按我想要的方式工作.任何帮助深表感谢.

谢谢!

uiviewanimation ios uistatusbar ios7

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

asp.net核心DI只注入单例,范围和瞬态不工作

我被困住了,我似乎无法解决这个问题.我有一个带接口的简单类.我正在将EFContext和Logger注入此服务.出于某种原因,无论我如何注册服务,它总是一个单身人士.我把Guid属性放在类上,看它是否在每个请求上都有变化,但它保持不变.

这是AccountService类及其接口:

public interface IAccountService 
{
    Account GetAccountByEmailAndPassword(string emailAddress, string password);
}

public class AccountService : IAccountService
{
    private readonly IEFContext _context;
    private readonly ILogger<AccountService> _logger;
    private string _guid;

    public AccountService()
    {
        _context = context;
        _logger = logger;
        _guid = Guid.NewGuid().ToString();
    }

    public Account GetAccountByEmailAndPassword(string emailAddress, string password)
    {
        try
        {
            //get the account
            var account = _context.Account.FirstOrDefault(x => x.EmailAddress == emailAddress);

            //make sure we have an account
            if (account == null)
                return null;

            //generate hash from account
            var accountHash …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection entity-framework-core asp.net-core-mvc asp.net-core

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

为什么在requestAccessToEntity中使用performSegueWithIdentifier时使用dispatch_async:completion?

当我在完成块中调用performSegueWithIdentifier时,如果我没有将调用包装在dispatch_async中,则实际发生segue需要10秒钟.但是,我可以做其他事情而不将它们包装在同一个dispatch_async中,例如进行核心数据工作,或者记录"事物"......

任何关于这如何工作的原因以及为什么......我迷失了.如果这不是问这样的事的正确的地方,我道歉.

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self performSegueWithIdentifier:self.phaseSegue sender:self];
    });
}];
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c ios uistoryboardsegue ekeventstore

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

Objective-C协议作为另一个协议的参数

我正在尝试创建一个访问我的web api的通用存储库(模式).我无法理解协议如何在objective-c中工作(我来自c#,其中接口有点不同).

我想要做的是让ProtocolA成为另一个ProtocolB中的参数,然后是ProtocolA上ProtocolB访问方法的实现,因为传入ProtocolB的对象必须实现ProtocolA本身.我正确地考虑了吗?

这就是我到目前为止所做的,但似乎无法让它发挥作用 - 也许我的逻辑错了:

//PGenericModel.h
@protocol PGenericModel <NSObject>
- (void)testMethod;
@end
Run Code Online (Sandbox Code Playgroud)


//PGenericRepository.h
#import "PGenericModel.h"
@protocol PGenericRepository <NSObject>
@required
- (void)Get:(id<PGenericModel>*)entity;
@end
Run Code Online (Sandbox Code Playgroud)


//GenericRepository.m
#import "GenericRepository.h"
@implementation GenericRepository
- (void)Get:(id<PGenericModel>*)entity
{
    //GET
    [entity testMethod] <-- this doesn't work...
}
@end
Run Code Online (Sandbox Code Playgroud)

objective-c objective-c-protocol

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