Tag: rubymotion

如何使用魔法logging来创build和更新对象,并保存它们而不使用contextForCurrentThread

我刚刚阅读MagicalRecord的博客文章的作者为什么contextForCurrentThread不能在MagicalRecord工作 。 不推荐使用saveWithBlock应使用saveWithBlock因为它为相关线程创build了一个安全的新NSManagedObjectContext 。 我一直在我的应用程序广泛使用contextForCurrentThread到目前为止。 然而,我很难找出如何使用saveWithBlock而我的提取和保存不一定顺序发生。 目前我正在做的事情如: localContext = NSManagedObjectContext.MR_contextForCurrentThread person = Person.MR_createInContext(localContext) person.name = "John Smith" 用户然后可以浏览应用程序,不同的控制器,视图等。 其他对象可以使用与上述代码类似的方法来创build。 然后在将来的某个任意点,当用户决定保存时,我运行这个方法: localContext = NSManagedObjectContext.MR_contextForCurrentThread localContext.MR_saveToPersistentStoreWithCompletion( lambda { |success, error| # … } ) 推荐的方法是创build和更新对象,然后保存它们而不使用contextForCurrentThread ?

使用RubyMotionselectiOS模拟器设备types

自iOS 8发布以来,模拟器的默认设备types变成了iPhone 6.即使我使用Hardware> Device菜单手动更改设备types,在下次启动(使用rake simulator )时,模拟器将恢复为iPhone 6。 我不知道是否有任何耙选项,或其他设置强制设备types。 PS。 我知道有办法强制一个非视网膜的iPhone和一种方式来启动iPad模拟器,而不是iPhone的,但我有兴趣在5/6/6 +之间进行select。 谢谢

如何为我的iOS导航栏创build水平渐变背景?

我知道如何设置一个导航栏背景颜色(与barTintColor),但现在我正在iOS应用程序,要求水平渐变(不是典型的垂直渐变)。 我如何创build一个水平渐变背景的导航栏?

如何获得有很多图像(50-200)snappy UICollectionView?

我在一个显示相当多的照片(50-200)的应用程序中使用UICollectionView ,我遇到的问题变得活泼(像照片应用程序一样快)。 我有一个自定义UICollectionViewCell与UIImageView作为它的子视图。 我将UIImage.imageWithContentsOfFile:从文件系统加载到单元格内的UIImageViews中。 现在我已经尝试了很多方法,但是它们一直是越野车或性能问题。 注意:我使用RubyMotion,所以我会用Ruby风格编写任何代码片段。 首先,这里是我的自定义UICollectionViewCell类供参考… class CustomCell < UICollectionViewCell def initWithFrame(rect) super @image_view = UIImageView.alloc.initWithFrame(self.bounds).tap do |iv| iv.contentMode = UIViewContentModeScaleAspectFill iv.clipsToBounds = true iv.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth self.contentView.addSubview(iv) end self end def prepareForReuse super @image_view.image = nil end def image=(image) @image_view.image = image end end 方法#1 保持简单 def collectionView(collection_view, cellForItemAtIndexPath: index_path) cell […]

AFNetworking请求错误代码999

我是新来的Objective-C,我很难与AFNetworking。 所以,事情是我想做一个简单的POST请求到一个服务器,谁会送我一个盐。 我做一个简单的应用程序,为了testing我的请求,但我不明白为什么我得到错误代码999。 这里是我的代码示例。 + (void)simpleRequest; { NSURL *mailserver = [NSURL URLWithString:@"https://localhost:4443/"]; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithBaseURL:mailserver]; manager.securityPolicy.allowInvalidCertificates = TRUE; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; NSDictionary *parameters = @{@"username": @"testtest"}; [manager POST:@"api/v0/login/salt" parameters:parameters success:^(NSURLSessionDataTask *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(NSURLSessionDataTask *operation, NSError *error) { NSLog(@"Error: %@", error); }]; } […]

如何使用UIButton作为切换button?

我正在尝试为表中的每个单元格创build一个切换button。 当按下时,它将改变图像,当再次按下它将再次改变图像 – 切换。 在UIButton类中,我看不到selected状态。 我正在寻找一种方法来创build与UIButton的切换button,以便我可以更改每次点击状态。 这就是我现在使用rmq在rubymotion做的rmq @fav_button.on(:touch) do |sender| puts "pressed fav button for id: " + data[:id] + " and name: " + data[:name] #how do I change the state here? end