我有一个表视图,加载时创建一个人对象
Person.h
#import <UIKit/UIKit.h>
#import "TwitterHelper.h"
@interface Person : NSObject {
NSDictionary *userInfo;
NSURL *image;
NSString *userName;
NSString *displayName;
NSArray *updates;
}
/*
@property (retain) NSString *userName;
@property (retain) NSString *displayName;
@property (retain) NSDictionary *userInfo;
*/
@property (nonatomic, copy) NSURL *image;
@property (retain) NSArray *updates;
- (id)initWithUserName:userName;
@end
Run Code Online (Sandbox Code Playgroud)
Person.m
#import "Person.h"
@implementation Person
/*
@synthesize userName;
@synthesize displayName;
@synthesize userInfo;
*/
@synthesize image;
@synthesize updates;
- (id)initWithUserName:(NSString *)user{
userName = user;
userInfo = [TwitterHelper fetchInfoForUsername:user];
displayName = [userInfo valueForKey:@"name"];
image …Run Code Online (Sandbox Code Playgroud) 我正在编写一个方法来返回给定字符是否有效,如下所示:
private static boolean isValid(char c) {
return c == '.' || c == ',' || c == '+' || c == '/' || c == ';' || c == ':';
}
Run Code Online (Sandbox Code Playgroud)
检查样式标记了这一点,因为布尔复杂度太大(5当它应该不超过3).我的开发经理已经标记了一些替代实现,我将作为答案发布.就个人而言,我认为我的代码足够可读,并且希望关闭此方法的检查样式.
你怎么看?
我在我的Asp.Net MVC应用程序中有一个表单,它在以下行返回Null引用异常,但仅在回发错误之后:
<%= Html.TextArea("Description", Model.Evt.Description ?? "")%>
Run Code Online (Sandbox Code Playgroud)
字符串描述确实是空的,但我的期望是,如果Model.evt.Description是,null那么""将显示在TextArea.为什么它在最初加载表单时工作正常呢?
唯一的区别是ViewUserControl的类型是从初始加载的新对象和回发重新加载的模型对象填充的.
我错过了什么?
堆栈跟踪如下:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Mvc.HtmlHelper.GetModelStateValue(String key, Type destinationType) +63
System.Web.Mvc.Html.TextAreaExtensions.TextAreaHelper(HtmlHelper htmlHelper, String name, Boolean useViewData, String value, IDictionary`2 implicitAttributes, IDictionary`2 explicitParameters, IDictionary`2 htmlAttributes) +261
System.Web.Mvc.Html.TextAreaExtensions.TextArea(HtmlHelper htmlHelper, String name, String value, IDictionary`2 htmlAttributes) +213
System.Web.Mvc.Html.TextAreaExtensions.TextArea(HtmlHelper htmlHelper, String name, String value) +61
ASP.views_events_eventform_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Documents and Settings\Richard Box\My Documents\Visual Studio 2008\Projects\EventsManager\EventsManager\Views\Events\EventForm.ascx:64
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) …Run Code Online (Sandbox Code Playgroud) 我将自己的C++ DateTime类定义为:
class DateTime
{
public:
int year;
int month;
int day;
int hour;
int min;
int sec;
int millisec;
};
Run Code Online (Sandbox Code Playgroud)
我有2个DateTime我需要比较,看看哪一个比另一个更大(更新).
DateTime我可以使用任何免费的C++ 类吗?
如果可以提供一个很好的具体例子.请注意,我需要比较毫秒.
我在考虑Boost或Qt.首选提升.
我有两张桌子:"餐馆"和"美食",它们通过HABTM表相互关联
餐桌美食有一定的固定条目 - 54号
餐厅可以提供任意数量的美食.在烘焙应用程序时,这带有多个选择.由于我想要复选框,我使用数组('type'=>'select','multiple'=>'复选框')将其转换为复选框.
现在我想按照下面的屏幕截图所示,将此复选框显示为4列的样式.
img2.pict.COM/82/BC/A4/1453459/0/200908111511.png
echo $form->input('Cuisine', array('type' => 'select', 'multiple' => 'checkbox'));
Run Code Online (Sandbox Code Playgroud)
上面的代码在每个元素周围产生许多div,如下所示
http://img2.pict.com/1a/a3/0a/1453457/0/200908121509.png
我尝试过以下方法:
echo $form->input('Cuisine', array( 'type' => 'select', 'multiple' => 'checkbox', 'div' => false, 'label' => false));
Run Code Online (Sandbox Code Playgroud)
但此代码仅删除外部div和标签.我无法控制内部
<div class="checkbox">
<label for="CuisineCuisine2">Andhra</label>
Run Code Online (Sandbox Code Playgroud)
出现在单个复选框周围.
我如何使用FormHelper删除或给内部div类,所以我可以做一些自定义样式?或者有没有其他方法来填充这个HABTM表来获得我想要的效果?
在windows7上安装sqlserver 2008 sp1时,当它到达'select features'部分时,列表为空.
由于我无法选择任何内容然后验证失败,我无法通过该步骤.
在windows7上安装sqlserver2008的人是一个真正的噩梦!
我有.net 3.5 SP1,尝试安装sqlserver 2008 SP1,它不会去任何地方.
我正处于一直在进行的项目的最后阶段.一切都运行顺利,但我有一个瓶颈,我无法解决.
我有一个元组列表.该列表的长度范围为40,000-1,000,000条记录.现在我有一个字典,其中每个(值,键)都是列表中的元组.
所以,我可能会
myList = [(20000, 11), (16000, 4), (14000, 9)...]
myDict = {11:20000, 9:14000, ...}
Run Code Online (Sandbox Code Playgroud)
我想从列表中删除每个(v,k)元组.
目前我在做:
for k, v in myDict.iteritems():
myList.remove((v, k))
Run Code Online (Sandbox Code Playgroud)
从包含20,000个元组的列表中删除838个元组需要3到4秒.我很可能会从1,000,000的列表中删除更多像10,000个元组,所以我需要更快.
有一个更好的方法吗?
我可以提供用于测试的代码,如果需要,还可以提供实际应用程序中的pickle数据.
我有一个这样的YAML文档:
---
version: 1
rootdirectory:
- subdirectory:
- file1
- file2
- subdirectory2
Run Code Online (Sandbox Code Playgroud)
我正在加载到这样的YAML :: Tiny对象:
$configuration = YAML::Tiny->read($configuration_file)
Run Code Online (Sandbox Code Playgroud)
我从使用Perl调试器调用脚本看到,我最终得到的是一组嵌套的哈希和数组,它们反映了YAML源的结构:
0 YAML::Tiny=ARRAY(0x84e3ba4)
0 HASH(0x80627dc)
'rootdirectory' => ARRAY(0x84e3d3c)
0 HASH(0x84352b0)
'subdirectory' => ARRAY(0x84e3df0)
0 'file1'
1 'file2'
1 'subdirectory2'
'version' => 1
Run Code Online (Sandbox Code Playgroud)
所以,我可以做以下事情而没有问题:
print $configuration->[0]->{version}
Run Code Online (Sandbox Code Playgroud)
并收到'1'的预期答案.同样,我也可以这样做:
print $configuration->[0]->{rootdirectory}->[0]->{subdirectory}->[0]
Run Code Online (Sandbox Code Playgroud)
并收到'file1'的预期答案.
我的问题来自于我在上面的例子中导出文件名所需的所有先验知识.因为我试图允许我的脚本的用户在YAML配置中描述任意目录结构,所以这还不够好.我需要能够从'rootdirectory'"走"树.
所以,我想我可以做到这样的事情:
print keys($configuration->[0])
Run Code Online (Sandbox Code Playgroud)
我原本应该返回'rootdirectory,version'......等等,遍历数组和哈希,直到我走过树.
当我尝试运行上面的例子时,我得到:
Type of arg 1 to keys must be hash (not array element)
Run Code Online (Sandbox Code Playgroud)
此时我被困住了.据我了解,$ configuration - > [0]虽然是数组的元素,但是包含哈希的元素我相信我应该可以调用key函数.
我在这里错过了什么?
我发现自己在ColdFusion中编写了这样的代码:
<cfset inputval = "" />
<cfif IsDefined("Form.Releases")>
<cfset inputval = Form.Releases />
</cfif>
Run Code Online (Sandbox Code Playgroud)
这非常麻烦.我只想将未定义的值转换为空字符串.有什么样的捷径吗?
例如,在PHP中我使用strval函数执行此操作,即:
$inputval = strval($_POST['Releases']);
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×1
c# ×1
c++ ×1
cakephp ×1
checkbox ×1
checkstyle ×1
clone ×1
cocoa ×1
coldfusion ×1
comparison ×1
cs193p ×1
datetime ×1
iphone ×1
java ×1
memory-leaks ×1
objective-c ×1
perl ×1
python ×1
scala ×1
sql-server ×1
styling ×1
syntax ×1
windows-7 ×1
yaml ×1