小编Seb*_*ger的帖子

UITableView:从空部分隐藏标题

我有一个UITableView,显示当月的费用(见截图):

我的问题是空部分的标题.有没有办法隐藏它们?数据从coredata加载.

这是生成标题标题的代码:

TitleForHeader

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
    return nil;
} else {

NSDate *today = [NSDate date ];
int todayInt = [dataHandler getDayNumber:today].intValue;

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:(-(todayInt-section-1)*60*60*24)];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]]];    
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
    return formattedDateString;}

}
Run Code Online (Sandbox Code Playgroud)

ViewForHeader

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
    return nil;
} else {

    UIView *headerView = …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview tableview ios

73
推荐指数
7
解决办法
6万
查看次数

Swift:选择一个随机枚举值

我试图随机选择一个枚举值,这是我目前的尝试:

enum GeometryClassification {

    case Circle
    case Square
    case Triangle
    case GeometryClassificationMax

}
Run Code Online (Sandbox Code Playgroud)

和随机选择:

let shapeGeometry = ( arc4random() % GeometryClassification.GeometryClassificationMax ) as GeometryClassification
Run Code Online (Sandbox Code Playgroud)

然而,这无可救药地失败了.

我得到的错误如下:

'GeometryClassification' is not convertible to 'UInt32'
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法?

random enums swift

22
推荐指数
5
解决办法
9233
查看次数

AWS Mobile HUD AWS SNS pushManagerDidRegister但未创建端点

我正在将AWS Mobile HUD与AWS SNS一起使用并遇到问题.

什么有效/已经完成了

  • 成功创建了p12通用证书
  • AWS HNS上的资源由Mobile HUD成功创建
  • Mobile HUD成功创建的主题
  • 将代码集成到项目中
  • 综合plist

以下代码应使用AWS SNS注册应用程序(设备):

pushManager = AWSPushManager(forKey: ServiceKey)
pushManager?.delegate = self
pushManager?.registerForPushNotifications()
Run Code Online (Sandbox Code Playgroud)

并且 - 足够大,func pushManagerDidRegister(_ pushManager: AWSPushManager)被称为成功.我func pushManagerDidRegister(_ pushManager: AWSPushManager)看起来像

func pushManagerDidRegister(_ pushManager: AWSPushManager) {
    print("Successfully enabled Push Notifications on platform: \(pushManager.platformARN)")
    // Subscribe the first topic among the configured topics (all-device topic)
    if let defaultSubscribeTopic = pushManager.topicARNs?.first {
        let topic = pushManager.topic(forTopicARN: defaultSubscribeTopic)
        topic.subscribe()
    }
}
Run Code Online (Sandbox Code Playgroud)

日志输出:

Successfully enabled Push Notifications on platform: …
Run Code Online (Sandbox Code Playgroud)

push-notification amazon-web-services amazon-sns ios swift

12
推荐指数
1
解决办法
258
查看次数

如何使用JPA和Hibernate修复StaleObjectStateException

控制器逻辑:

def updateObject() {

    Object o = Object.get(params.id as Long)

    o.otherObjects.clear()

    objectDataService.saveObject(o.id)

    OtherObject newObject = new OtherObject;

    o.addToOtherObjects(newObject)

    objectDataService.saveObject(o.id)

}
Run Code Online (Sandbox Code Playgroud)

ServiceLogic

def saveObject(long profileId) {
    o.save(flush:true)
}
Run Code Online (Sandbox Code Playgroud)

怎么了

在90%的情况下,这将起作用.

问题

ERROR errors.GrailsExceptionResolver  - StaleObjectStateException occurred when processing request: [GET] /controller/updateObject - parameters:
stuff[]: data
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.path.Object#1]. 
Stacktrace follows:
Message: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.path.Object#1]
Run Code Online (Sandbox Code Playgroud)

我已阅读相关问题并找到merge您在上面看到的电话.它解决了大约50%的案例,但并非全部.

grails hibernate grails-orm staleobjectstate

11
推荐指数
3
解决办法
2万
查看次数

SecurityException:Permission Denial:打开提供程序

我有以下问题.我们创建了一个游戏中心应用程序,它提供了一个框架来创建临时wifi游戏并管理这些游戏的高分/遭遇.

高分的数据库访问是通过提供者完成的:

<provider     
    android:name="com.identifier.gamecenterapp.contentprovider.MyGamesContentProvider"
    android:authorities="com.identifier.gamecenterapp.contentprovider" >
</provider>
Run Code Online (Sandbox Code Playgroud)

我们的演示游戏(作为未来游戏开发者的参考)包含以下权限:

<uses-permission android:name="com.identifier.gamecenterapp.contentprovider.READ_DATABASE"/>
<uses-permission android:name="com.identifier.gamecenterapp.contentprovider.WRITE_DATABASE"/>
Run Code Online (Sandbox Code Playgroud)

现在 - 每当我们尝试使用游戏访问提供程序时,都会收到以下错误:

09-17 12:15:52.221: E/AndroidRuntime(4551): FATAL EXCEPTION: main
09-17 12:15:52.221: E/AndroidRuntime(4551): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.identifier.gamecenter.gctictactoe/com.identifier.gamecenter.game.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.identifier.gamecenterapp.contentprovider.MyGamesContentProvider from ProcessRecord{42622078 4551:com.identifier.gamecenter.gctictactoe/u0a10108} (pid=4551, uid=10108) that is not exported from uid 10072
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 12:15:52.221: E/AndroidRuntime(4551):     at android.os.Looper.loop(Looper.java:137)
09-17 12:15:52.221: …
Run Code Online (Sandbox Code Playgroud)

permissions android android-contentprovider android-4.3-jelly-bean

10
推荐指数
1
解决办法
2万
查看次数

AWSS3 Region/plist配置问题'服务配置为`nil`

我正面临着AWSS3的一个奇怪问题.

建立:

  • AWS Mobile HUB
  • Cognito
  • DynamoDB
  • S3

- > Cognito,Dynamo甚至S3(通过cognito用户数据)工作.

但是我现在尝试使用以下代码直接连接到AWS3:"

let transferManager = AWSS3TransferManager.default()
                            let uploadRequest = AWSS3TransferManagerUploadRequest()
                            uploadRequest?.bucket = "XXXXXXXXXXXX"
                            uploadRequest?.key = "user-data/" + awsId! + "/primary_profile_picture.png"
                            uploadRequest?.body = imgUrl as URL

                            transferManager.upload(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in

                                if let error = task.error as? NSError {
                                    if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
                                        switch code {
                                        case .cancelled, .paused:
                                            break
                                        default:
                                            print("Error uploading: \(uploadRequest?.key) Error: \(error)")
                                        }
                                    } else {
                                        print("Error uploading: …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services ios swift

9
推荐指数
2
解决办法
7803
查看次数

Xcode 4.6在plist文件中的本地化

我已经开始在我的项目中添加更多语言,并且本地化的字符串和图形没有太多麻烦.

我有一个最后一个问题,它是一个plist文件.

此plist文件包含应用程序的默认类别名称,并在字典中填充英文字符串.

我的问题是:有没有办法本地化plist文件?我虽然要向plist添加本地化字符串,但无法弄清楚如何.

我不想在代码中决定使用plist文件,因为默认的plist文件在首次使用时被用户覆盖.

xcode localization objective-c plist

8
推荐指数
1
解决办法
7994
查看次数

iCloud键值存储同步问题(未调用NSUbiquitousKeyValueStoreDidChangeExternallyNotification)

我正在为iOS编写一个小型通用游戏.高分将通过iCloud Key/Value商店在设备上同步.

获得最新分数:

func retrieveHighestScore() -> Int64 {
        let iCloudScore: Int64 = NSUbiquitousKeyValueStore.defaultStore().longLongForKey(KeyValueKeyClassification.KeyHighscore.toRaw())
        let localScore: Int64 = Int64(NSUserDefaults.standardUserDefaults().integerForKey(KeyValueKeyClassification.KeyHighscore.toRaw()))
        var result: Int64 = 0

        if localScore > iCloudScore {
            storeNewHighscore(localScore)
            result = localScore
        } else {
            storeNewHighscore(iCloudScore)
            result = iCloudScore
        }
        return result
    }
Run Code Online (Sandbox Code Playgroud)

存储新的高分

func storeNewHighscore(newScore: Int64) {
        NSUbiquitousKeyValueStore.defaultStore().setLongLong(newScore, forKey: KeyValueKeyClassification.KeyHighscore.toRaw())
        NSUserDefaults.standardUserDefaults().setInteger(Int(newScore), forKey: KeyValueKeyClassification.KeyHighscore.toRaw())
        if NSUbiquitousKeyValueStore.defaultStore().synchronize() {
            println("Synched Successfully")
        }
    }
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,分数不同步.

  • 没有错误
  • 没有崩溃
  • 没有空值

我总是得到当前设备的最高分,而不是其他设备.

原因可能在于itunesconnect还是我的代码有问题?我正在使用ipad和iphone进行测试,两者都登录到我自己的icloud帐户.

我正在注册这样的更改:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override …
Run Code Online (Sandbox Code Playgroud)

xcode ios icloud swift ios8

7
推荐指数
1
解决办法
1776
查看次数

重命名持久性存储区协调器URL

我有一个(可以)简单的修复我的coredata持久性商店的问题.

我创建它:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{

    if (persistentStoreCoordinator != nil)
    {
        return persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"dummyURL.sqlite"];

    NSError *error = nil;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }  

    return persistentStoreCoordinator;
}
Run Code Online (Sandbox Code Playgroud)

使用网址 dummyURL.sqlite

我在使用该项目的第一天就这样做了,并且忘记了重命名..现在我所有现有的测试设备(4)都在使用超过2个月,使用该应用程序,收集大量数据并存储它一个愚蠢的网址^^

更新我做了一些关于持久性存储迁移的研究并编写了这个函数:

-(void)migrate{

    NSPersistentStoreCoordinator *psc = [self.dataHandler.managedObjectContext persistentStoreCoordinator];
    NSURL *oldURL = [psc URLForPersistentStore:[[psc persistentStores]objectAtIndex:0]];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    NSURL *newURL = [[appDelegate applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"]; …
Run Code Online (Sandbox Code Playgroud)

iphone core-data objective-c ios

6
推荐指数
1
解决办法
1362
查看次数

Markdown 图像未显示

我正在使用markdown prohttp://www.markdownpro.com/)编写一些降价文档

不知何故,并非我添加的所有图像都显示在最终文档中:

我这样添加它们

<img src="./img/clv.png" height="100"/>
Run Code Online (Sandbox Code Playgroud)

但结果看起来是这样的

在此输入图像描述

文件结构如下所示:

在此输入图像描述

而“summary”是我的 .md 文件

我也尝试过 markdown 语法

![](./img/clv.png)
Run Code Online (Sandbox Code Playgroud)

和明确的结束标签

<img></img>
Run Code Online (Sandbox Code Playgroud)

但总是得到相同的结果,没有显示图像。

我尝试过的其他方法:

<img src="./img/clv.png" height="100"/>
<img src="../img/clv.png" height="100"/>
<img src="img/clv.png" height="100"/>
<img src="~/img/clv.png" height="100"/>
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

html markdown

5
推荐指数
1
解决办法
3322
查看次数