小编fes*_*fes的帖子

c#Abstract实现接口的类

我已经看到以下代码布局阅读论坛和其他博客文章,并进行了调整,以便提出几个问题.

public interface IService<T>
{
    int Add(T entity);
    void Update(T entity);
}

public abstract class ServiceBase<T> : IService<T>
{
    public int Add(T entity) { ... }
    public void Update(T entity) { ... }
}

public interface ICarService : IService<Car>
{
}

public class SomeBaseClass : ServiceBase<Car>, ICarService
{
    public int Add(Car entity);
    public void Update(Car entity);
}
Run Code Online (Sandbox Code Playgroud)

我不明白的是让抽象类实现接口的好处.对我来说,它只是感觉有点重复,我无法理解实现接口的抽象类的好处.

  1. 为什么抽象类ServiceBase<T>只是定义为不需要继承IService接口?这会使代码翻倍吗?
  2. 为什么SomeBaseClass还必须加入ICarService?ServiceBase不应该足够吗?

c# interface abstract

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

UITableView多个复选标记选择

在阅读了与此相关的几个问题之后,我可以使用该功能.但是我的列表很长且可滚动,所以当我向上和向下滚动时,选中的复选标记就到处都是.selectedIndexes是一个NSMutableArray.有任何想法吗?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
        [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
        [selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];

    } 
    else {
        [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
        [selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];

    }

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

}
Run Code Online (Sandbox Code Playgroud)

在我的cellForRowAtIndexPath:我有以下检查.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSDictionary *dictionary = [natures objectAtIndex:indexPath.section]; …
Run Code Online (Sandbox Code Playgroud)

selection uitableview

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

UITableView背景颜色

我已经在UITableView for ios 4.2上看过各种关于背景颜色的帖子,但我似乎无法改变背景颜色.

UIView *bgView = [[[UIView alloc] init] autorelease];
bgView.backgroundColor = [UIColor blackColor];
bgView.opaque = YES;
self.myTableView.backgroundView = bgView;
Run Code Online (Sandbox Code Playgroud)

我已将此代码放在viewDidLoad中,但它不会更改颜色.我的UITableView是UIViewController里面的一个IBOutlet,带有UITableViewDelegate和UITableViewDataSource,所以我想在viewDidLoad中UITableView已经渲染,我无法改变它的背景颜色.

编辑* - UITableView被分组

uitableview ipad

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

Clear Canvas Rect(但保留背景)

我正在尝试动画一个圆圈,只是水平移动它,工作正常.然而,当圆圈移动时,我必须对该圆圈执行clearRect,以便在水平方向上重新绘制它.当我做一个clearRect时,它也会使背景周围有白框,这样它就会在圆圈移动的方向上成为一条白色的水平线.

  1. 有没有办法在没有clearRect的情况下清除圆圈?
  2. 如果我必须在clearRect之后继续重新绘制背景,那么当theres说10个圆圈在那个区域移动时,画布将会闪烁.

还有其他解决方法吗?

    function drawcircle() {
        clear();    

        context.beginPath();
        context.arc(X, Y, R, 0, 2*Math.PI, false);                  
        context.moveTo(X,Y);            
        context.lineWidth = 0.3;
        context.strokeStyle = "#999999"; 
        context.stroke();

        if (X > 200)
        {
            clearTimeout(t); //stop
        }
        else
        {
            //move in x dir
            X += dX;
            t = setTimeout(drawcircle, 50);
        }
    }

    function clear() {
        context.clearRect(X-R, Y-R, 2*R, 2*R);
    }
Run Code Online (Sandbox Code Playgroud)

html drawing canvas

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

流畅的API - 一对多

我似乎无法在流畅的API中找到一对多的关系语法.

作为一个例子,我有两个表如下

用户

Id
Name
Run Code Online (Sandbox Code Playgroud)

UserHistory

Id
UserId
Date
Run Code Online (Sandbox Code Playgroud)

在课程中,我有以下内容

public class User 
{
     public int Id { get; set; }
     public virtual ICollection<UserHistory> Histories { get; set; }
}

public class UserHistory
{
     public int Id { get; set; }
     public int UserId { get; set; }
     public DateTime Date { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我尝试过以下但我不确定它是否真的正确.

modelBuilder.Entity<User>()
       .HasRequired(w => w.Histories)
       .WithMany();

modelBuilder.Entity<User>()
       .HasMany(f => f.Histories)
       .WithOptional()
       .HasForeignKey(f => f.UserId);
Run Code Online (Sandbox Code Playgroud)

一对多关系的正确语法是什么?

从技术上讲,我可以通过添加新表将其分解为多对多,但我不想引入另一个表.

entity-framework-5

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

UITableView没有滚动

我有一个使用UITableViewDelegate和UITableViewDataSource的UIViewController.我用大约20个自定义UITableViewCells创建了UITableView,而不是所有那些UITableViewCell都适合屏幕.当然,你会认为它是可以滚动至底部,看看其他UITableViewCells,但它不检测滚动的一切让我看不到底部的项目.

我的AppDelegate有一个UINavigationController,我刚刚添加了它

[window addSubview:navigationController.view]

导航控制器内的视图控制器实现了一个

@interface MainViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
Run Code Online (Sandbox Code Playgroud)

我所做的只是创建一个UINavigationController应用程序,因此默认情况下UITableView属性应该是默认属性.

我的MainViewController XIB有

  • 视图
    • 表视图
    • 表视图单元格
    • 表视图单元格
    • 表视图单元格
    • 另外15个表视图单元格

从上面我不知道我是如何修改默认的UITableView,因为我没有以任何方式配置它.

UITableView呈现我想要的,但是当我想看到底部的UITableViewCells时,它根本就不滚动.

uitableview ipad ios

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

MVC3相对URL路径 - Javascript

我有一个相对路径的问题,当Web应用程序在域的子目录中运行时,路径不正确.例如http://www.domain.com/webapp/

如果我在页面上使用@ Url.Content("〜/ path/to/action")就可以了.我甚至可以在javascript脚本中嵌入@ Url.Content("").我想清理我想把javascript放在js文件中的页面并引用它.现在,在javascript文件中调用@ Url.Content,它似乎不起作用(可能是出于显而易见的原因).我该如何解决这个问题?

我看了一眼,@Url.Content("~/path/to/action")但这似乎不起作用.

javascript url path relative-path asp.net-mvc-3

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

UIColor到十六进制(网页颜色)

有一种简单的方法可以转换UIColor为十六进制值吗?
或者我们是否必须使用RGB组件,CGColorGetComponents然后从那里开始工作?

例如CGColorGetComponents(color.CGColor)[0] * 256

uikit uicolor ios

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

IE9显示IE7用户代理

我正在使用IE9测试来自VS2010的应用程序,一切正常,然后突然IE9浏览器奇怪地决定它想成为IE7.当我查询navigator.userAgent时,它会提供IE7用户代理.那是怎么回事?!

现在IE9一直在想它IE7.我以前从未使用过IE7!?

user-agent internet-explorer-9

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

迭代接口列表

我有一个类似T对象的接口,如此

public interface IService<T>
Run Code Online (Sandbox Code Playgroud)

我有一堆这些接口与所有不同类型的T.如何将这些接口添加到某种列表中,遍历列表并调用接口使用的常用方法.有任何想法吗?有替代方法吗?

如果我将它添加到列表中,我就是看不到正确地转换类型T的方法.

c#

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