我遇到了一个针对Android和iOS构建的PhoneGap应用程序的问题.在iOS和大多数Android设备上,除三星Galaxy S3和S4外,它的功能完美.
在第一页加载时,应用程序会创建一个本地SQL数据库.此数据库用于存储整个应用程序中的问题和答案的值.
我在三星设备上遇到的问题是,第一次运行应用程序时数据库无法正常加载,但是如果用户完全关闭应用程序并重新打开它,则会创建没有错误的数据库.由于第一页要求用户输入其年龄,然后将值存储在SQL数据库中,因此用户会得到应用程序此时已冻结的印象.
数据库的初始化代码:
的index.html
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
populateDB();
}
Run Code Online (Sandbox Code Playgroud)
main_js.js
function populateDB() {
var db = window.openDatabase("Database", "1.0", "My Database", 20000);
db.transaction(populate_DB, errorCB, successCB);
}
function populate_DB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Options (ID INTEGER UNIQUE NOT NULL, Name TEXT NOT NULL, Value INTEGER NOT NULL)');
tx.executeSql('CREATE TABLE IF NOT EXISTS Questions (ID INTEGER UNIQUE NOT NULL, Question TEXT NOT NULL, Answer TEXT)');
tx.executeSql('INSERT OR IGNORE INTO Options (ID, Name, Value) VALUES (1, "License", …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的应用程序示例,初始化和更新用户位置..在设备上它成功地每隔一秒左右抛出另一个回调位置但是在设备上(运行iOS7的iPhone)调用该方法一次然后神秘地停止...
//Setup Location Manager in ViewDidLoad
locationManager = [[CLLocationManager alloc] init];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"location services not turned on");
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"loactions %@", locations);
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"new location %f, and old %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
在iOS6中,这个应用程序完美无缺地更新了设备位置...自iOS7以来发生了哪些变化?
我有一个UITableView,它由JSON文件中的文本和图像填充.TableView单元格当前正在为文本中没有包含很多换行符的"帖子"正确调整大小,但我无法通过4或5个换行符来计算"帖子"的正确高度.
获得身高的代码:
-(float)height :(NSMutableAttributedString*)string
{
NSString *stringToSize = [NSString stringWithFormat:@"%@", string];
CGSize constraint = CGSizeMake(LABEL_WIDTH - (LABEL_MARGIN *2), 2000.f);
CGSize size = [stringToSize sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:contraint lineBreakMode:NSLineBreakByWordWrapping];
return size.height;
}
Run Code Online (Sandbox Code Playgroud)
如何在允许换行和空白的同时计算正确的尺寸?
其余的方法,
在TableView CellForRow中:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *row = [NSString stringWithFormat:@"%i", indexPath.row];
float postTextHeight = [self height:postText];
NSString *height = [NSString stringWithFormat:@"%f", heightOfPostText + 70];
[_cellSizes setObject:height forKey:row];
}
Run Code Online (Sandbox Code Playgroud)
和表格单元格的高度:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *imageHeightString = [NSString stringWithFormat:@"%@", [_cellSizes objectForKey:indexPath.row]];
float heightOfCell = [imageHeightString …Run Code Online (Sandbox Code Playgroud) 目前我有14个按钮使用for循环以编程方式创建,代码如下:
int buttonCount = 14;
for (int i=0; i< buttonCount; i++) {
//Create titleString from array object
NSString *stringFromInt = [NSString stringWithFormat:@"%@",[arrayForRound objectAtIndex:i]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(buttonSelected:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:stringFromInt forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"helvetica" size:19];
button.tag = i;
[self.view addSubview:button];
}
Run Code Online (Sandbox Code Playgroud)
这非常适合创建按钮,然后我可以使用所选按钮的值填充答案框:
-(void)buttonSelected: (UIButton *)sender
{
[_buttonOne setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud)
但是,在填充按钮后,我想将其从屏幕上删除.如果我调用button.hidden它只是隐藏了以编程方式创建的最后一个按钮.我知道button.tag并试图使用它,但感觉我几乎需要做类似的事情:
//Hide button for tag (i know this is incorrect syntax)
button for buttonTag: 3 setHidden;
Run Code Online (Sandbox Code Playgroud)
是否有相似或类似的方法?
我试图隐藏的按钮是以编程方式创建的按钮.所以我希望_buttonOne采用创建按钮的标题(让我们调用那个letterButton),然后从视图中隐藏letterButton,
UIButton *yourBtn = (UIButton *)[self.button viewWithTag:3]; …Run Code Online (Sandbox Code Playgroud) 你好,这是一个简单的问题.是否可以更改当前位于iTunes连接但没有上传二进制文件的应用程序的详细信息.
例如,我想开始开发和测试inApp购买,但应用程序还没有完成屏幕截图和图标等的阶段...所以如果我创建应用程序ID等,并将其添加到iTunes商店与黑色图像截图可以在批准之前更改吗?
谢谢T
ios ×2
objective-c ×2
android ×1
cordova ×1
ios7 ×1
javascript ×1
sql ×1
sqlite ×1
uibutton ×1
uitableview ×1
xcode ×1