我有一些核心數據代碼需要運行IF textView1 textViewDidEndEditing。然後停止並不從textView2 swell 運行代碼,截至目前,我只是運行textViewDidEndEditing中的所有代碼。即使我有一個if語句。但我做錯了。因爲它運行來自兩個IF語句的代碼...UITextView +2在viewcontroller中。 textViewDidEndEditing調用兩次,如何管理它?
它是如何使它僅在textView1完成編輯時才運行? 這就是做編輯
- (void)textViewDidEndEditing:(UITextView *)textView{
if ((textView = textView1)){
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_defaultContext];
TextView *aTextView = [TextView MR_createEntity];
aTextView.belongsTo = @"jegKomTil1";
// Build the predicate to find the person sought
NSString *predicateString = [NSString stringWithFormat:@"jegKomTil1"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"belongsTo == %@", predicateString];
TextView *aTextView1 = [TextView MR_findFirstWithPredicate:predicate inContext:localContext];
// If a person was founded
if (aTextView1) { // Update its age
aTextView1.textDataView = textView1.text;
}
[localContext MR_saveToPersistentStoreAndWait];
}
if ((textView = textView2)){
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_defaultContext];
TextView *aTextView = [TextView MR_createEntity];
aTextView.belongsTo = @"jegKomTil2";
// Build the predicate to find the person sought
NSString *predicateString = [NSString stringWithFormat:@"jegKomTil2"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"belongsTo == %@", predicateString];
TextView *aTextView1 = [TextView MR_findFirstWithPredicate:predicate inContext:localContext];
// If a person was founded
if (aTextView1) { // Update its age
aTextView1.textDataView = textView2.text;
}
[localContext MR_saveToPersistentStoreAndWait];
NSLog(@"textViewDidEndEditing: 2");
}
如果(TextView的== textView1之間的唯一區別真)。 (看到區別?) –
@ nickfalk是啊我注意到了區別。但它會工作,或者我應該做什麼igrekde設置爲答案? – KennyVB
它應該工作得很好。我不知道你打算讓應用最終做什麼,但是檢查一個對象實例可能沒問題。我寧願讓你給他們更明確的名字,比使用標籤,因爲標籤不會真的讀得那麼好... –