小编rei*_*ein的帖子

如何打印方法名称和行号并有条件地禁用NSLog?

我正在做一个关于在Xcode中调试的演示文稿,并希望获得有关使用NSLog的更多信息.

特别是,我有两个问题:

  • 有没有办法轻松NSLog当前方法的名称/行号?
  • 有没有办法在编译发布代码之前轻松"禁用"所有NSLog?

xcode cocoa cocoa-touch objective-c nslog

446
推荐指数
11
解决办法
14万
查看次数

检测在UITableView中按下了哪个UIButton

我有一个UITableView5 UITableViewCells.每个单元格包含一个UIButton设置如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString *identifier = @"identifier";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
     if (cell == nil) {
         cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
         [cell autorelelase];

         UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, 40, 20)];
         [button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
         [button setTag:1];
         [cell.contentView addSubview:button];

         [button release];
     }

     UIButton *button = (UIButton *)[cell viewWithTag:1];
     [button setTitle:@"Edit" forState:UIControlStateNormal];

     return cell;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:在buttonPressedAction:方法中,我如何知道按下了哪个按钮.我考虑过使用标签,但我不确定这是最好的路线.我希望能够以某种方式标记indexPath到控件上.

- (void)buttonPressedAction:(id)sender
{
    UIButton *button = (UIButton …
Run Code Online (Sandbox Code Playgroud)

iphone uibutton uitableview ios

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

UITableView中节标题的默认高度

我想在UITableView中设置第一个标题的高度.对于其他标题,我希望它们保持默认高度.在下面的代码中,我可以用什么值/常数代替"someDefaultHeight"?

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return kFirstHeaderHeight;

    return someDefaultHeight;
}
Run Code Online (Sandbox Code Playgroud)

谢谢

iphone cocoa-touch uitableview

123
推荐指数
5
解决办法
8万
查看次数

在.NET中从URL读取字符串的最简单方法

给定字符串中的URL:

http://www.example.com/test.xml
Run Code Online (Sandbox Code Playgroud)

将文件内容从服务器(由url指向)下载到C#中的字符串中,最简单/最简洁的方法是什么?

我现在这样做的方式是:

WebRequest request = WebRequest.Create("http://www.example.com/test.xml");
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

这是很多代码,基本上可以是一行:

string responseFromServer = ????.GetStringFromUrl("http://www.example.com/test.xml");
Run Code Online (Sandbox Code Playgroud)

注意:我不担心异步调用 - 这不是生产代码.

c# networking http

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

风格的不同:IDictionary与Dictionary

我有一个朋友刚刚开始使用Java开发.NET开发很长时间,在查看了他的一些代码后,我注意到他经常做以下事情:

IDictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>();
Run Code Online (Sandbox Code Playgroud)

他将字典声明为接口而不是类.通常我会做以下事情:

Dictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>();
Run Code Online (Sandbox Code Playgroud)

我只在需要时使用IDictionary接口(例如,将字典传递给接受IDictionary接口的方法).

我的问题是:他的做事方式有什么优点吗?这是Java中的常见做法吗?

.net c# java interface

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

使用TSQL确定表的主键

我想使用TSQL确定表的主键(存储过程或系统表很好).SQL Server(2005或2008)中是否存在这样的机制?

sql t-sql sql-server primary-key

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

UITableViewCell中的复选框图像切换

我需要一些关于创建UITableViewCell的指导,左边有一个可以切换的图像.图像应该是可插拔的,并充当切换(复选框).

我正在努力的部分是:

  1. 如何检测图像上的点击并以不同的方式处理didSelectRowAtIndexPath?
  2. 如何在不执行[tableView reloadData]的情况下更改图像?

有关示例,请参见下图:

替代文字http://img208.yfrog.com/img208/6119/screenshotkmr.png

谢谢

iphone cocoa-touch uitableview

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

.NET中dll的版本号

鉴于以下内容:

string file = @"c:\somepath\somefile.dll";
Run Code Online (Sandbox Code Playgroud)

如何使用.NET查找该DLL的文件和产品版本号?

dll可以是本机的或托管的.

谢谢.

.net c# versioning dll

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

绘制透明按钮

我正在尝试在C#(.NET 3.5 SP1)中创建一个透明按钮,以便在我的WinForms应用程序中使用.我已经尝试了一切让按钮变得透明(它应该显示按钮下方的渐变背景)但它只是不起作用.

这是我正在使用的代码:

public class ImageButton : ButtonBase, IButtonControl
{
    public ImageButton()
    {
        this.SetStyle(
            ControlStyles.SupportsTransparentBackColor | 
            ControlStyles.OptimizedDoubleBuffer | 
            ControlStyles.AllPaintingInWmPaint | 
            ControlStyles.ResizeRedraw | 
            ControlStyles.UserPaint, true);
        this.BackColor = Color.Transparent;
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
        Graphics g = pevent.Graphics;
        g.FillRectangle(Brushes.Transparent, this.ClientRectangle);
        g.DrawRectangle(Pens.Black, this.ClientRectangle);
    }


    // rest of class here...

}
Run Code Online (Sandbox Code Playgroud)

问题是该按钮似乎是从某个地方抓取随机UI内存并从Visual Studio的UI中填充一些缓冲区(在设计模式下).在运行时它会抓住一些零缓冲区并且完全是黑色的.

我的最终目标是在隐形按钮而不是矩形上绘制图像.然而,这个概念应该保持不变.当用户将鼠标悬停在按钮上时,则绘制按钮类型的形状.

有任何想法吗?

编辑:谢谢大家,以下为我工作:

public class ImageButton : Control, IButtonControl
{
    public ImageButton()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        SetStyle(ControlStyles.Opaque, true);
        SetStyle(ControlStyles.ResizeRedraw, true);
        this.BackColor = Color.Transparent;

    }

    protected override void OnPaint(PaintEventArgs pevent) …
Run Code Online (Sandbox Code Playgroud)

c# gdi+ button winforms

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

发布Core Foundation对象引用

我是否需要释放Core Foundation对象以清理内存?如果是这样,怎么样?

例如,在代码中:

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook);
Run Code Online (Sandbox Code Playgroud)

我需要发布peopleArray吗?怎么样addressBook

cocoa cocoa-touch objective-c core-foundation

20
推荐指数
2
解决办法
8174
查看次数