2014-07-05 73 views
0

我最近問了一個類似的問題,但是轉向了另一種解決方案,但現在我發現我確實需要在另一個領域中使用它。我的應用跟蹤參加錦標賽的玩家。每個玩家都會檢入,然後將他們的匹配添加到數據庫中。每個玩家可以在多天內辦理登機手續,所以有一對多的關係。每場比賽可以有兩名球員,球員可以有多場比賽,所以球員和比賽是多種關係。核心數據關係中的對象謂詞

我有三個實體:播放器,CHECKIN,並且匹配

球員實體< - >>簽入實體 球員實體< < - >>比賽實體

的Player.h:

@class CheckIn, Match; 
@interface Player : NSManagedObject 

@property (nonatomic, retain) NSDate * birthDay; 
@property (nonatomic, retain) NSString * email; 
@property (nonatomic, retain) NSString * firstName; 
@property (nonatomic, retain) NSString * lastName; 
@property (nonatomic, retain) NSString * playerID; 
@property (nonatomic, retain) NSString * playerImage; 
@property (nonatomic, retain) NSString * playerImageSmall; 
@property (nonatomic, retain) NSDate * timeOfLastCheckIn; 
@property (nonatomic, retain) NSNumber * isCheckedIn; 
@property (nonatomic, retain) NSOrderedSet *playerCheckIns; 
@property (nonatomic, retain) NSSet *playerMatches; 
@end 

@interface Player (CoreDataGeneratedAccessors) 

- (void)insertObject:(CheckIn *)value inPlayerCheckInsAtIndex:(NSUInteger)idx; 
- (void)removeObjectFromPlayerCheckInsAtIndex:(NSUInteger)idx; 
- (void)insertPlayerCheckIns:(NSArray *)value atIndexes:(NSIndexSet *)indexes; 
- (void)removePlayerCheckInsAtIndexes:(NSIndexSet *)indexes; 
- (void)replaceObjectInPlayerCheckInsAtIndex:(NSUInteger)idx withObject:(CheckIn *)value; 
- (void)replacePlayerCheckInsAtIndexes:(NSIndexSet *)indexes withPlayerCheckIns:(NSArray *)values; 
- (void)addPlayerCheckInsObject:(CheckIn *)value; 
- (void)removePlayerCheckInsObject:(CheckIn *)value; 
- (void)addPlayerCheckIns:(NSOrderedSet *)values; 
- (void)removePlayerCheckIns:(NSOrderedSet *)values; 
- (void)addPlayerMatchesObject:(Match *)value; 
- (void)removePlayerMatchesObject:(Match *)value; 
- (void)addPlayerMatches:(NSSet *)values; 
- (void)removePlayerMatches:(NSSet *)values; 
@end 

CheckIn.h:

@class Player; 

@interface CheckIn : NSManagedObject 
@property (nonatomic, retain) NSNumber * challengeBadge; 
@property (nonatomic, retain) NSDate * checkInTime; 
@property (nonatomic, retain) NSString * player; //convenience string with player's full name 
@property (nonatomic, retain) NSNumber * spiritBadge; 
@property (nonatomic, retain) NSNumber * stampsBadge; 
@property (nonatomic, retain) NSNumber * triviaBadge; 
@property (nonatomic, retain) Player *checkedInPlayer; 
@end 

Match.h

@class Player; 

@interface Match : NSManagedObject 
@property (nonatomic, retain) NSString * playerOne; //convenience string with player's full name 
@property (nonatomic, retain) NSString * playerTwo; //convenience string with player's full name 
@property (nonatomic, retain) NSDate * time; 
@property (nonatomic, retain) NSString * winner; //convenience string with player's full name 
@property (nonatomic, retain) NSOrderedSet *matchPlayers; 
@end 

@interface Match (CoreDataGeneratedAccessors) 

- (void)insertObject:(Player *)value inMatchPlayersAtIndex:(NSUInteger)idx; 
- (void)removeObjectFromMatchPlayersAtIndex:(NSUInteger)idx; 
- (void)insertMatchPlayers:(NSArray *)value atIndexes:(NSIndexSet *)indexes; 
- (void)removeMatchPlayersAtIndexes:(NSIndexSet *)indexes; 
- (void)replaceObjectInMatchPlayersAtIndex:(NSUInteger)idx withObject:(Player *)value; 
- (void)replaceMatchPlayersAtIndexes:(NSIndexSet *)indexes withMatchPlayers:(NSArray *)values; 
- (void)addMatchPlayersObject:(Player *)value; 
- (void)removeMatchPlayersObject:(Player *)value; 
- (void)addMatchPlayers:(NSOrderedSet *)values; 
- (void)removeMatchPlayers:(NSOrderedSet *)values; 
@end 

我的模型的玩家實體有這些關係: playerCheckIns爲CHECKIN與逆checkedInPlayers playerMatches與逆matchPlayers來匹配(這是有序並具有2最大值)

的比賽管理員用戶將使用桌面查看所有球員。對於每個玩家來說,他們都需要查看玩家所在比賽的列表以及玩家擁有的簽入列表。我想爲每個可以應用於我的CheckIn tableview和Match tableview的謂詞分別使用謂詞。這並不相關,但我正在使用SWTableViewCell將實用程序按鈕放入自定義tableviewcells中,並設置手動segues來處理導航。匹配和簽入視圖控制器都有一個NSPredicate *謂詞,用於處理入站謂詞。

當管理員用戶在玩家單元格中選擇匹配實用程序按鈕時,我想加載我的匹配表視圖,傳遞一個謂詞來過濾視圖以僅顯示所選玩家參與的匹配項。這將住在我的prepareforsegue方法中,以獲得適當的segue標識符。

這就是我現在對我的球員的tableview的prepareforsegue方法匹配:

Player *currentPlayer = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]]; 
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SUBQUERY(match, $m, ANY $m.matchPlayers == %@)[email protected] > 0", currentPlayer]; 
NSLog(@"Setting predicate: %@",pred); 
filteredMatchVC.predicate = pred; 

我的NSLog揭示了謂詞設定爲:

SUBQUERY(match, $m, ANY $m.matchPlayers == nil)[email protected] > 0 

因此,currentPlayer對象沒有被捕獲在謂詞中。

到過濾簽入視圖的轉換是相似的,但我沒有試過,但由於這個錯誤...

任何幫助,不勝感激!

回答

0

傷口通過使用按鈕的單元格對象作爲發送者爲segue ...