考虑这个简单的模型:
基本位置表:
+-------------------------------+
| Locations |
+-------------------------------+
|(PK) _id Integer Autoincrement |
| name Text(100) Not null |
| is_in_range Integer |
+-------------------------------+
Run Code Online (Sandbox Code Playgroud)
更专业的表叫做WifiLocation:
+-------------------------------+
| wifi_location |
+-------------------------------+
| ssid Text(0) Not null |
| signal_threshold Real |
|(PK) _id Integer |
+-------------------------------+
Run Code Online (Sandbox Code Playgroud)
我希望这个模型代表一个WifiLocation继承自BaseLocation.所以我在表REFERENCES的_id列上添加了一个子句,如下wifi_locations所示:
CREATE TABLE wifi_locations (_id Integer primary key references Locations(_id), ....)
Run Code Online (Sandbox Code Playgroud)
我试图在这些表之间建立1:1的关系.
当我想向wifi_locations表中插入一行时,我首先将适当的值(Name,IsInRange)插入Locations表中,然后返回rowId.然后我将其余的数据(ssid)wifi_locations与rowId一起作为外键插入到表中.
所以插入到Location表是有效的,我正在返回一个Id,但是当我尝试使用这个Id并将其插入到wifi_locations表时,我收到了一个SQL Constraint violation错误.关于究竟出了什么问题没有更多细节.
我的架构有什么问题吗?有没有更好的方法来实现这种建模? …
我试图从我的发布数据发送到我的服务器的图像从android.为了实现这一点,我将64位编码的我的图像编码为字符串并使用android volley库发送它.但这会引起问题.由于某种原因,它有时会发送两次帖子,我无法弄清楚原因.下面是调用发送post请求的函数.我在那里放了一个破记标记,String url = "http://domain.com/ajax_ws.php";然后在protected Map<String, String> getParams() {我发现的String url = ...内容中只有一个被调用一次但是当它发送两个时,它protected Map...被调用两次.我在android排球上找不到任何文档,所以我不知道为什么会这样.调整位图大小,使图像字符串始终保持在100k到200k字符之间.我想也许这是一个大小问题,但我的服务器正在接收图像并解码它们,一切都很好.
public void Sharing() {
pd = ProgressDialog.show(getParent(), null, "Please Wait...");
final String caption = mEtMessage.getText().toString();
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://domain.com/ajax_ws.php";
StringRequest postRequest = new StringRequest(
Request.Method.POST,
url,
new MyStringListener(),
new MyErrorListener()
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("token", "secretToken");
params.put("mode", "createVoucher");
params.put("user_id", ActivityLogin.id);
params.put("deal_id", ActivitySharing.id_deal);
params.put("user_id_company", ActivityRestaurantDetails.res.getId()); …Run Code Online (Sandbox Code Playgroud) 我正在构建一个将在多个iOS应用程序中使用的静态库.与此同时,我正在使用我的库处理其中一个应用程序.
在开发过程中,我每天至少会遇到一个令人烦恼的错误,即有关未找到库的头文件(在我的应用程序项目中).我了解到,建立一个静态库时,标题可以是Public,Private或Project
我猜我想要在我的库中公开的每一个标题都应该是Public.
我的问题是,管理这些公共标题的最佳方法是什么?我应该#import为所有公共标题创建一个主公共头文件吗?Xcode可以为我生成这样的文件吗?
另一个主要问题是建议的推荐值是Public Header Folder Path多少?
我的主要目标是将来使用此库的项目将能够以尽可能少的配置(添加链接器标志,更改User Header Search Path等)执行此操作.
非常感谢你.
有人问我怎样才能改变const变量的值.
我明显的回答是"指针!" 但我尝试了下一段代码,我很困惑......
int main()
{
const int x = 5;
int *ptr = (int *)(&x); // "Cast away" the const-ness..
cout << "Value at " << ptr << ":"<< (*ptr) <<endl;
*ptr = 6;
cout << "Now the value of "<< ptr << " is: " << (*ptr) <<endl;
cout << "But the value of x is still " << x <<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
Value at <some address> :5
Now the value of <same address> is: 6 …Run Code Online (Sandbox Code Playgroud) 我有一个包含项目名称的数组.我想让用户选择创建项目而不指定其名称,因此我的程序必须提供唯一的默认名称,如"Item 1".
挑战是名称必须是唯一的,所以我必须检查所有数组的默认名称,如果有一个具有相同名称的项目,我必须将名称更改为"项目2",依此类推,直到我找到可用的名称.
显而易见的解决方案是这样的:
String name = "Item ";
for (int i = 0; !isAvailable(name + i) ; i++);
Run Code Online (Sandbox Code Playgroud)
我的算法问题是它运行在O(N ^ 2).
我想知道是否有一种已知的(或新的)更有效的算法来解决这种情况.
换句话说,我的问题是:是否有任何算法可以找到在给定数组中不存在的第一个大于零的数字,并且运行的数量少于N ^ 2?
我正在开发一个应用程序,用户可以选择是否要扫描条形码或拍摄某些内容.为了拍照,我UIImagePickerController照常使用.对于扫描条形码,我使用的是ZbarSDK 1.2 ZBarReaderViewController.
拍照时一切都很完美.扫描条形码时:如果您在拍照前启动应用程序并扫描条形码,它也可以完美运行.
但是你是拍照,然后回去尝试扫描条形码,相机失去了自动对焦,而且扫描条形码是不可能的.
总结一下:
开始 - >扫描 - > 自动对焦工作
开始 - >拍照 - >返回 - >扫描 - > 自动对焦不工作
这是我初始化条形码扫描仪的方式:
-(ZBarReaderViewController *) barcodeScanner
{
if (nil == _barcodeScanner)
{
_barcodeScanner = [ZBarReaderViewController new];
_barcodeScanner.readerDelegate = self;
_barcodeScanner.cameraMode = ZBarReaderControllerCameraModeSampling;
_barcodeScanner.sourceType = UIImagePickerControllerSourceTypeCamera;
}
return _barcodeScanner;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在尝试获取所有新ActionBar和Fragments API的句柄.我有一个主要活动,我希望它管理两个不同的选项卡.我正在使用ActionBarSherlock以支持比ICS更旧的版本.
每个选项卡都包含它自己Fragment(每个都是它的子类SherlockListFragment)我让它工作基本上很好,但我有一个问题,我确定这是愚蠢的,但我还是无法解决它:
在第一次显示每个片段时,一切正常,列表已填充,因此ActionBtem位于ActionBar中.
但是第二次看到一个标签(在swicth和switch-back之后),列表都没有填充,也没有ActionBar MenuItems.
这是我切换标签的方式:
@Override
public void onTabSelected(Tab tab, FragmentTransaction transaction) {
SherlockListFragment toAttach = // Find the right fragment here...
if (toAttach != null) {
if (toAttach.isAdded() == false) {
transaction.add(R.id.tab_placeholder, toAttach,
REMINDER_FRAGMENT_TAG);
} else {
transaction.attach(toAttach);
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且onTabUneselect我正在分离碎片:
@Override
public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
SherlockListFragment toDetach = // Find the right fragment
if (toDetach != null) {
transaction.detach(toDetach);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在onResume中填充列表和ActionBar菜单:
@Override
public void onResume() {
super.onResume(); …Run Code Online (Sandbox Code Playgroud) java android android-fragments actionbarsherlock android-actionbar
我为PopoverController创建了自己的类(没有子类化UIPopoverController)以我想要的方式呈现ViewControllers.
CustomPopoverController不是UIViewController,而是有一个名为"contentViewController"的ivar,它实际上是显示的VC.
当用户点击contentViewController框架之外的任何地方时,我实现了自己的"dismissPopoverAnimated:"以解除我的自定义弹出窗口:
-(void) dismissPopoverAnimated : (BOOL) animated
{
// dismissalView is the view that intercept the taps outside.
[self.dismissalView removeFromSuperview];
self.dismissalView = nil;
if (animated)
{
CGRect newFrame = self.view.frame;
// When in landscape Mode the width of the screen is actually the "height"
newFrame.origin.y = [UIScreen mainScreen].bounds.size.width;
[UIView animateWithDuration:0.5
animations:^{self.view.frame = newFrame;}
completion: ^(BOOL finished) {if(finished) [self.contentViewController.view removeFromSuperview];}];
}
else
{
[self.contentViewController.view removeFromSuperview];
}
isPresented = NO;
[self.delegate customPopoverDidDismissPopover:self];
}
Run Code Online (Sandbox Code Playgroud)
问题是,即使removeFromSuperView在任何情况下被调用 - 动画与否,contentViewController永远不会接收viewWillDisappear …
在 Tornado 中不是很有经验,如果这听起来像一个新手问题,那么抱歉。
我正在使用标准的 html/js 代码和服务器上的龙卷风与客户端构建纸牌游戏。一切正常,但是我需要在服务器上实现倒计时,在一定时间后运行某个代码。我正在使用以下 python 代码并在发出请求后从龙卷风中调用它
import time
class StartTimer(object):
timerSeconds = 0
def __init__(self):
print "start timer initiated"
def initiateTime(self, countDownSeconds):
self.timerSeconds = countDownSeconds
while self.timerSeconds >= 0:
time.sleep(1)
print self.timerSeconds
self.timerSeconds -=1
if self.timerSeconds == 0:
#countdown finishes
print "timer finished run the code"
def getTimer(self):
return self.timerSeconds
Run Code Online (Sandbox Code Playgroud)
倒计时工作正常,但是我首先有两个问题,而计时器正在倒计时服务器会阻止任何其他连接并将它们放入队列并在计时器第二次完成后运行代码,我需要 getTimer 函数才能工作,所以一个新的进来的客户知道还剩多少时间(基本上是获取 timerSeconds 值)。我可以摆脱不向用户显示的计时器,但是代码被阻止的事实绝对不好。
请帮忙
我有一个执行Wifi P2p发现的代码,向用户显示附近的设备,让他选择他想要连接的设备.
该发现按预期工作,但当我尝试实际连接到所选设备时,系统调用ActionListener.onFailure并传递"内部错误"的原因代码.
这是启动连接的代码:
public void connectToDevice(WifiP2pDevice device) {
Log.i(TAG, "Initiating connection to " + device.deviceAddress);
stopScan();
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
// Since we wish to send a friend request, it will be easier if
// we'll end up as a client because we will have the group owner's
// address immediately.
config.groupOwnerIntent = 0;
mP2pManager.connect(mChannel, config, mConnectionListener);
}
Run Code Online (Sandbox Code Playgroud)
并mConnectionListener定义如下:
protected ActionListener mConnectionListener = new ActionListener() {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我有以下C数组NSString *:
static NSString *const OrderByValueNames[] = {@"None",@"Added",@"Views",@"Rating",@"ABC",@"Meta"};
Run Code Online (Sandbox Code Playgroud)
现在,我想在运行时检查这个数组的长度,所以我编写了以下方法:
NSInteger LengthOfArray(NSString *const array[])
{
NSInteger length = 0;
// For Loop Without a body!
for (length = 0; array[length] != nil; length++);
return length;
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在debug配置中运行此代码时,一切都很好,函数返回正确的结果.
但是一旦我切换到release配置并再次运行它,程序就会在for循环中冻结.在执行循环10秒后,iOS会杀死应用程序以便不响应.奇怪的.
现在,如果我将循环添加到循环中,就像这样:
for (length = 0; array[length] != nil; length++)
{
NSLog(@"%d",length);
}
Run Code Online (Sandbox Code Playgroud)
然后即使在发布模式下也能正常工作.
给循环一个空体,就像那样:
for (length = 0; array[length] != nil; length++){}
Run Code Online (Sandbox Code Playgroud)
在发布模式下仍然冻结.
我的猜测是在发布模式下运行时有一个编译器优化,但具体到底是什么?!
有任何想法吗?