在NSMutableArray和Sqlite中存储CGPoints(Storing CGPoints in NSMutableArray and Sqlite)
每当touchesMoved被调用时,我都希望存储这些点。 到目前为止一切工作正常。 但是我想要做的是每次触摸移动被调用时创建一个“新”数组。 例如,一旦触摸结束,点数组将被保存到标识符为1的数据库中。下次调用touchesMoved时,数组将被清空,并用具有不同标识符的另一组点替换。 每次调用时,我都会尝试在touchesEnded中增加一个整数,但我发现每次触摸结束时整数都会保持不变。 那么我将如何做到这一点? 任何帮助将非常感激。
更新:例如,我在我的数组中记录了这些点:
100.000, 200.000 100.000, 202.000 100.000, 204.000
这些点将用一个标识符保存在数据库中,比方说1。
1 | 100.000 | 200.000 1 | 100.000 | 202.000 1 | 100.000 | 204.000
现在,当触摸移动并再次结束时,新的一组记录点将以不同的标识符保存,比如2。
2 | 200.000 | 300.000 2 | 200.000 | 302.000 2 | 200.000 | 304.000
所以基本上我想要发生的是每次touchesMoved被调用时,它都会记录将被保存在数组中的点。 当触摸结束时,这个记录点将被保存一个标识符。 并且,一旦touchesMoved被再次调用并结束,新的一组记录点将以不同的标识符保存。 任何想法如何做到这一点?
I would like to store the points whenever touchesMoved is called. So far everything is working fine. However what I want to do is to create a "new" array every time touchesMoved is called. For example, once the touch ended the array of points are then saved into database with an identifier of 1. The next time the touchesMoved is called, the array is emptied and replaced with another set of points with a different identifier. I tried incrementing an integer in touchesEnded every time it is called, but I figured out that the integer will remain the same every time the touch ended. So how will I do this? Any help will be very much appreciated.
UPDATE: For example I have this recorded points in my array:
100.000, 200.000 100.000, 202.000 100.000, 204.000
This points will be saved in the database with a identifier, let's say 1.
1 | 100.000 | 200.000 1 | 100.000 | 202.000 1 | 100.000 | 204.000
Now, when the touches moved and ended again, the new set of recorded points will be saved with a different identifier, let's say 2.
2 | 200.000 | 300.000 2 | 200.000 | 302.000 2 | 200.000 | 304.000
So basically what I want to happen is that every time the touchesMoved is called, it will record points that will be saved in an array. When the touches ended, this recorded points will be saved with an identifier. AND, once the touchesMoved is called again and ended, the new set of recorded points will be saved with a different identifier. Any ideas how to do it?
原文:https://stackoverflow.com/questions/11079686
最满意答案
要创建一个合适的python
list
对象,你可以这样做ar = [int(i) for i in input().split()]
否则,这样做
ar = map(int, input().split())
如果需要,您还可以删除额外的空格。 做
ar = map(int, input().strip().split())
To create a proper python
list
object, you can doar = [int(i) for i in input().split()]
Otherwise, Do it this way
ar = map(int, input().split())
You can also strip extra whitespace if needed. Do
ar = map(int, input().strip().split())
相关问答
更多-
如何自动生成一些Python代码格式正确的代码?(How do I autoformat some Python code to be correctly formatted?)[2023-08-14]
编辑:现在,我会推荐autopep8 ,因为它不仅可以纠正缩进问题,还可以(根据您的判断)使代码符合许多其他PEP8指南。 使用reindent.py 。 它应该带有标准的Python发行版,尽管在Ubuntu上你需要安装python2.6-examples包。 你也可以在网上找到它。 该脚本尝试转换任何python脚本以符合4空间标准。 Edit: Nowadays, I would recommend autopep8, since it not only corrects indentation pr ... -
>>> print "%r, %r" % (True, False) True, False 这不是布尔值特定的 - %r调用参数上的__repr__方法。 %s (对于str )也应该有效。 >>> print "%r, %r" % (True, False) True, False This is not specific to boolean values - %r calls the __repr__ method on the argument. %s (for str) should als ...
-
该输入应该可以用std::getline或std::regex_token_iterator进行解析(尽管后者是用大炮射击麻雀)。 例子: 正则表达式 快速和肮脏,但重量级的解决方案 (使用提升,所以大多数编译器吃这个) #include
#include int main() { const std::string s = "\"MARY\",\"PATRICIA\",\"LINDA\",\"BARBARA\",\"ELIZABETH\" ... -
使用double {{和}} : "{{'key_1': '{value}'}}".format(**{'value': 'test'}) Use double {{and }}: "{{'key_1': '{value}'}}".format(**{'value': 'test'})
-
您可以在日期时间对象的 strftime使用相同的格式化字符串: >>> import datetime >>> datetime.datetime.now().strftime('%b-%d-%I%M%p-%G') 'May-16-0245PM-2011' 顺便提一句,我只想说一句ISO-8601日期格式化的喜悦 :) You can use the same formatting string in strftime on a datetime object: >>> import datetime ...
-
要创建一个合适的python list对象,你可以这样做 ar = [int(i) for i in input().split()] 否则,这样做 ar = map(int, input().split()) 如果需要,您还可以删除额外的空格。 做 ar = map(int, input().strip().split()) To create a proper python list object, you can do ar = [int(i) for i in input().split()] ...
-
yourVar = "Total of the sale is: ${:,.2f}".format(TotalAmount) yourVar = "Total of the sale is: ${:,.2f}".format(TotalAmount)
-
虽然它不是先验明显的,但是有一种相对简单的方法可以改变流认为是空白的内容。 这样做的方法是使用std::locale对象来imbue()流,其中std::ctype
facet被替换为将所需的字符视为空格。 imbue() , locale , ctype - 呵呵?!? 好的,好吧,这些不一定是你日常使用的东西所以这里是一个快速的例子,它设置了std::cin以逗号和换行符号作为间隔使用: #include template struct ... -
要在':'之前允许可选空格,请替换 "%d:%d" 同 "%d :%d" sscanf()忽略空格,其格式指令告诉它忽略,而不是无处不在。 指令中的空白字符(如' '将忽略所有空格。 %d以及其他整数和浮点指令将忽略前导空格。 因此, %d之前的空间是多余的。 C11 7,21,6,2,8跳过输入空格字符(由isspace函数指定),除非规范包含[,c或n说明符。) 其他注意事项包括使用%u和unsigned作为不接受负数的替代方法。 strptime()是用于扫描字符串以获取时间信息的常用函数。 To ...
-
为此,您可以将字符串拆分为3个部分(第一组字母,数字,然后是第二组字母)。 然后你可以使用s.isalpha()和s.isnumeric() 。 例如: while True: c=input('Password: ') if len(c)==7 and c[:2].isalpha() and c[2:4].isnumeric() and c[4:].isalpha(): break else: print('Invalid input') print ...