我正在研究我的第一个RestKit应用程序,并使用CoreData进行本地缓存.在其中我有Post << --- >> Category之间的多对多关系.这种关系称为帖子和类别.
在我的Post JSON调用中,我获得了类似这样的类别{"post": [...] "categories":[1,4] [...]
的id:,其中1和4是id.
我有一个Post
继承自定义的模型对象NSManagedObject
,在其中我有类别的属性,如下所示:
@interface Post : NSManagedObject
[...]
@property (nonatomic, retain) NSSet *categories;
[...]
Run Code Online (Sandbox Code Playgroud)
我在自定义的Category模型对象中做同样的事情.
我的映射目前看起来像这样:
RKManagedObjectMapping *categoryMapping = [RKManagedObjectMapping mappingForClass:[Category class] inManagedObjectStore:objectManager.objectStore];
categoryMapping.primaryKeyAttribute = @"categoryId";
categoryMapping.rootKeyPath = @"categories";
[categoryMapping mapKeyPath:@"id" toAttribute:@"categoryId"];
[categoryMapping mapKeyPath:@"name" toAttribute:@"name"];
[...]
RKManagedObjectMapping* postMapping = [RKManagedObjectMapping mappingForClass:[Post class] inManagedObjectStore:objectManager.objectStore];
postMapping.primaryKeyAttribute = @"postId";
postMapping.rootKeyPath = @"post";
[postMapping mapKeyPath:@"id" toAttribute:@"postId"];
[...]
[postMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"];
[...]
// Categories many-to-many.
[postMapping mapKeyPath:@"categories" toRelationship:@"categories" withMapping:categoryMapping];
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到错误: '[<__NSCFNumber …
我正在开发一个应用程序,我想对服务器进行远程搜索.我希望RestKit将检索到的数据保存到数据库中.我首先执行本地搜索(当前有效),然后我想进行远程搜索,然后使用新结果更新表格视图.
我有两个问题,1.我的映射应该如何; 2. json返回一个包含两种不同对象的数组.
URL如下所示:
search.json?search=[search string]
Run Code Online (Sandbox Code Playgroud)
它返回的JSON如下所示:
[
{
"event": {
"id": 2,
[...]
},
{
"news": {
"id": 16,
[...]
}
Run Code Online (Sandbox Code Playgroud)
事件和新闻是两种对象.
在我的应用程序中,我有三个模型,Post(抽象实体和超类)NewsPost(子类到Post)和Event(子类到Post).
我的映射看起来像这样:
RKManagedObjectMapping* newsMapping = [RKManagedObjectMapping mappingForClass:[NewsPost class] inManagedObjectStore:objectManager.objectStore];
newsMapping.primaryKeyAttribute = @"newsId";
newsMapping.rootKeyPath = @"news";
[newsMapping mapKeyPath:@"id" toAttribute:@"newsId"];
RKManagedObjectMapping *eventMapping = [RKManagedObjectMapping mappingForClass:[CalendarEvent class] inManagedObjectStore:objectManager.objectStore];
eventMapping.primaryKeyAttribute = @"calendarId";
eventMapping.rootKeyPath = @"calendars";
[eventMapping mapKeyPath:@"id" toAttribute:@"calendarId"];
// These two works.
[objectManager.mappingProvider setObjectMapping:newsMapping forResourcePathPattern:@"/package_components/1/news"];
[objectManager.mappingProvider setObjectMapping:eventMapping forResourcePathPattern:@"/package_components/1/calendars"];
// I don't know how these should look/work.
// Since the search …
Run Code Online (Sandbox Code Playgroud) 我刚用iAP发布了我的第一个应用程序.它在开发中总是运行良好,但在生产中,当我尝试购买时它会崩溃.
似乎应用程序不能在生产模式下载我的"产品".有没有其他人有类似的问题,你做了什么来解决它?
我正在为一个网站使用 Twitter Bootstrap。我试图让内容居中。传统上,我会简单地创建一个如下所示的自定义.container
类:
.container {
width: 70%;
max-width: 1024px;
margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
我试图手动覆盖这个类,但似乎只有宽度有所不同。我将内容放在容器中,如下所示:
<div class="container>
<div ng-view></div>
</div>
Run Code Online (Sandbox Code Playgroud)
容器本身是居中的。但是里面的内容似乎有左边距/填充。关于我应该如何构建我的 div 的任何想法?
更新
我使用Bootstrap v3.0.3
我有一个 NSDate,我想要将小时、分钟和秒归零。我想要的结果是:2014-02-19 00:00:00 +0000
。我已经尝试过以下方法:
NSUInteger flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents* components = [[NSCalendar currentCalendar] components:flags fromDate:self.birthDatePicker.date];
NSDate* birthDate = [[NSCalendar currentCalendar] dateFromComponents:components];
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我得到了这个:2014-02-19 23:00:00 +0000
。小时没有归零。我也尝试过设置[components setHour:0]
。但我几个小时都得到相同的结果23
。关于我做错了什么有什么想法吗?
我正在尝试为iOS创建一个简单的聊天应用程序.它目前看起来像这样:
我想更改消息显示的顺序,即显示旧消息的最新消息.我目前的实现如下:
// Datasource for the tableView
messages = [[NSMutableArray alloc] init];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[...]
// messageTextView is a contentView subView.
messageTextView.text = [messages objectAtIndex:indexPath.row];
[...]
- (IBAction)sendMessage:(id)sender
{
[messages addObject:messageField.text];
messageField.text = @"";
[self.tableView reloadData];
/*
I have tried the implementation below, but I always got an exception.
[self.tableView beginUpdates];
NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0];
NSArray * indexArray = [NSArray arrayWithObjects:path1,nil];
[self.tableView insertRowsAtIndexPaths:indexArray
withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
*/
Run Code Online (Sandbox Code Playgroud)
}
任何有关如何做到这一点的提示都会很棒.
谢谢.
我第一次使用UICollectionView
.我正在尝试获取每个单元格的"行"值 - 用作单元格文本字段的标识符/标记.当cellForItemAtIndexPath
被调用时,它看起来像[indexPath row];
回归nil
.当行为零时,如何获取单元格索引(或其他用作标识符的内容)?
注意 使用iOS7,如果这有任何区别......
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Returns nil
NSLog("Row: %d", indexPath.row);
}
Run Code Online (Sandbox Code Playgroud)
有什么想法/提示吗?
我money-rails
在Rails应用程序中使用了gem。到目前为止,它一直运行良好,但是最近我开始出现以下错误:
Money#== supports only zero numerics
Run Code Online (Sandbox Code Playgroud)
我不确定这是什么原因或如何解决。我最近跑步,bundle update
所以我想有些东西已经更新。我的gemfile
样子是这样的:
gem 'money-rails', '~>1'
gem 'eu_central_bank', "~>1.3.0"
Run Code Online (Sandbox Code Playgroud)
我的实现如下所示:
# model
monetize :price_in_cents
# fetch / converting currencies
eu_bank = EuCentralBank.new
Money.default_bank = eu_bank
eu_bank.update_rates
converted_price = eu_bank.exchange_with(Money.new(price_to_convert * 100, from_currency), to_currency)
Run Code Online (Sandbox Code Playgroud)
正如我之前提到的那样,这已经解决了,所以我不确定是什么在破坏它。
有任何想法吗?
更新资料
为了测试,我尝试了以下方法。
money = Money.new(100, from_currency)
Run Code Online (Sandbox Code Playgroud)
然后我得到了和以前一样的错误。但是,如果我尝试过:
money = Money.new(0, from_currency)
Run Code Online (Sandbox Code Playgroud)
它似乎有效。我觉得有点奇怪。
更新资料
这是我尝试保存记录时的回溯信息:
[“ /Users/[user]/.rvm/gems/ruby-2.5.1/gems/money-6.11.3/lib/money/money/arithmetic.rb:70:in!= =='", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations/numericality.rb:22:in
'”,“ / Users / [user] /。rvm / gems / ruby-2.5.1 / gems / activemodel-5.1.6 / lib …
我有一个看起来像这样的数据模型:
Location <------->> Item
Run Code Online (Sandbox Code Playgroud)
每个位置可以有很多项目.我想在a中显示这些位置和项目UICollectionView
.我希望每个位置都是包含项目的部分.像这样:
-----------------------
I Location 1 I
-----------------------
I Item 1 I Item 2 I
I--------- I-----------
I Location 2 I
-----------------------
[...]
Run Code Online (Sandbox Code Playgroud)
我想知道哪种方式最好达到这个目的?我之前从未使用过部分,所以我不确定这是不是正确的方法.如果是这样的话,我如何将位置作为部分,然后在这些部分中显示项目?
我目前的非工作实现如下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
return [sectionInfo numberOfObjects];
}
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate. …
Run Code Online (Sandbox Code Playgroud) 我在我的Rails应用程序中使用Bootstrap,在其中我有一个包含一些元素的导航栏.当我按下其中一个元素时,我会出现一个模态弹出窗口.当我关闭此弹出窗口时,由于某种原因所点击的元素会突出显示.这不是我正在寻找的经验.
见下图:
我想知道如何摆脱这种不必要的影响?
ios ×7
cocoa-touch ×4
objective-c ×4
core-data ×3
css ×2
html ×2
restkit ×2
angularjs ×1
currency ×1
iphone ×1
javascript ×1
jquery ×1
many-to-many ×1
money-rails ×1
nsdate ×1
nsindexpath ×1
ruby ×1
search ×1