我已经为UIButton创建了一个子类,并希望将自定义属性传递给它.然而,它不起作用,我已经读过,继承UIButton并不是一个好主意.
我的问题是如何为按钮分配自定义属性?我正在创建一个按钮,该按钮被放置在分组表的标题视图中.我想传递给那个按钮的节号.我已经在每行中使用UISwitch成功完成了此操作,但不能对UIButton使用相同的方法.
所以我创建了一个按钮
MattsButtonClass *button = [MattsButtonClass buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(240, 15, 45, 30);
button.MFsectionNo = section; //this would be 1, 2 etc
//etc
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做呢?你会看到我的UI按钮有一个子类,看起来像这样
//.h file
@interface MattsButtonClass : UIButton {
int MFsectionNo;
}
@property (nonatomic) int MFsectionNo;
@end
//.m file
@implementation MattsButtonClass
@synthesize MFsectionNo;
@end
Run Code Online (Sandbox Code Playgroud)
上面的错误是
-[UIRoundedRectButton MFsectionNo:]: unrecognized selector sent to instance 0x5673650
2010-09-07 22:41:39.751 demo4[67445:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIRoundedRectButton MFsectionNo:]: unrecognized selector sent to instance 0x5673650'
Run Code Online (Sandbox Code Playgroud)
我不想做什么?谢谢你的帮助...
我在上面看过这个例子 documentation for PHP readfile
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Run Code Online (Sandbox Code Playgroud)
你怎么能这样做它下载多个文件说monkey.gif和girraffe.jpg
最好没有 ZIP 档案......
默认情况下,如果您在输入文本时摇动iPhone UITextField,则会出现一个小框,询问您是否要撤消输入.我怎样才能防止这种情况发生?我查看了UITextField,UITextFieldDelegate和UITextInputTraits文档,发现没有任何关于摇晃的内容.
据推测,我可以继承UITextField忽略震动事件,但我对自己不能搞砸其他事情的能力并不完全有信心.我喜欢类似的东西
textField.respondsToShake = FALSE;
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?
我是单元测试的新手,我一直在学习如何使用jUnit框架用于android(使用ActivityInstrumentationTestCase2),但我在如何将模拟数据源注入和活动时遇到了麻烦,例如:
在活动中我有这个
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState,R.layout.market_screen);
ListView products = (ListView)findViewById(R.id.product_list);
MarketsAdapter adapter = new MarketsAdapter(this, new ProductDataSource());
products.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
我目前将ProductDataSource传递给适配器,该适配器连接到web服务以引入适配器的产品.在我的测试中,我不想连接到webservice.将模拟数据源注入活动进行测试的最佳技术是什么?我应该在Application实例中创建ProductDataSource,然后在我的测试中使用MockApplication来创建模拟数据源吗?
谢谢
我通过在测试类setUp()方法中执行以下操作来解决:获取对它的引用ListView并使用设置模拟数据源setAdapter(MockDataSource).这必须在UI线程上使用runOnUiThread()方法运行.
mActivity = getActivity();
mDataSource = new FakeDataSource();
mMarketsListView = (ListView)mActivity.findViewById(R.id.product_list);
mActivity.runOnUiThread(
new Runnable() {
public void run() {
mMarketsListView.setAdapter(new MarketsAdapter(mActivity,mDataSource));
} // end of run() method definition
} // end of anonymous Runnable object instantiation
); //
Run Code Online (Sandbox Code Playgroud) JFrame.setResizable(true)让用户调整窗口的宽度和高度.是否存在允许用户仅调整高度的方法?
谢谢.
编辑:下面的解决方案似乎不起作用.在360x600 JFrame上,
setResizable(true);
pack();
setMaximizedBounds(new java.awt.Rectangle(0, 0, 360, 1200));
setMaximumSize(new java.awt.Dimension(360, 1200));
setMinimumSize(new java.awt.Dimension(360, 600));
setPreferredSize(new java.awt.Dimension(360, 600));
setVisible(true);
Run Code Online (Sandbox Code Playgroud)
仍然允许完全拉伸JFrame的宽度,并且设置setResizable(false)不允许任何拉伸.
当我这样做时,script/runner它给了我-bash: script/runner: Permission denied
当我这样做sudo script/runner时给了我sudo: script/runner: command not found
它只适用于我ruby script/runner.为什么?在其他任何地方,我看到人们只是在script/runner没有ruby前面的情况下运行......是否有"修复"?它导致我的javan-每当生成的crontab失败时,Permission denied因为它只运行script/runner没有ruby...
我在C++工作,我有一个#define VAL 0x00000400.当我设置一个等于define:int value = VAL的变量时; 当我运行调试器时显示变量值= 1024.有人可以解释如何变成1024吗?也许有一些链接到内存地址信息,#define信息或相关的东西.
我试图让我的程序忽略Ctrl+ C在unix中似乎工作,问题是它继续写"语法错误".这是代码
extern "C" void ignore( int sig )
{
fprintf( stderr, "\n"); // Print a new line
// This function does nothing except ignore ctrl-c
}
int main()
{
// For ctrl-c
sigset( SIGINT, ignore );
while (1) {
getUserInput();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
每次我点击Ctrl+ C它再次运行getUserInput,这是预期的行为,但它也写了"语法错误".我检查并执行"忽略"函数,一旦执行完毕,它就会输出错误信息,我不知道为什么.
有人有任何线索吗?
非常感谢你,
Jary
StyleCop有一个关于使用"this"的规则.调用类成员的前缀(SA1101).
这个规则是否适用于从其基类继承的类的成员(例如方法).
例:
class BaseClass
{
protected void F1()
{
...
}
}
class ChildClass : BaseClass
{
protected void F2()
{
...
}
protected void F3()
{
this.F2(); // This is correct acording to SA1101
// F1 is a member of base class and if I dont put this prefix, stylecop will not show any message.
this.F1(); // Is this correct?
F1(); // Or this?
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这只是为了更好的可读性.
我正在使用PyQt4和QtWebKit进行一些工作,并且在网页请求中需要发送自定义"主机"标头以及标准HTTP请求.我没有看到任何为请求添加自定义标头的选项,但这对我来说都是新的,所以我希望我错过了一些东西.我在这看:
http://doc.qt.digia.com/4.6/qwebsettings.html
任何建议将不胜感激.
iphone ×2
unix ×2
adapter ×1
android ×1
c ×1
c# ×1
c++ ×1
coding-style ×1
cron ×1
download ×1
file ×1
header ×1
java ×1
jframe ×1
listview ×1
memory ×1
objective-c ×1
php ×1
pyqt ×1
pyqt4 ×1
qtwebkit ×1
resizable ×1
ruby ×1
shake ×1
stylecop ×1
swing ×1
this ×1
uibutton ×1
uitextfield ×1
unit-testing ×1
webkit ×1
whenever ×1