我有一个 iPad 应用程序,使用 XCode 4.5、Storyboards、Core Data 和 iOS 6。我选择一行,对记录的内容进行更改(成功),但该行没有改变。我试图刷新 UITableView,但从未调用cellForRowAtIndexPath 。我搜索了 SO 和 Google 无济于事;我看不出有什么问题。有人可以告诉我如何解决这个问题吗?(解释我下次做错了什么?)
以下是相关代码:
- (IBAction)btnModify:(UIButton *)sender {
//NSLog(@"btnModify clicked");
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
// find client by primary telephone number
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"aClientPrimaryPhone ==[c] %@", cvPrimaryPhone.text];
ClientInfo *clientDataFound = [ClientInfo MR_findFirstWithPredicate:predicate inContext:localContext];
if(clientDataFound) {
clientDataFound.aClientName = cvCustName.text; // now start moving the data
clientDataFound.aClientAddr1 = cvAddress1.text;
clientDataFound.aClientAddr2 = cvAddress2.text;
clientDataFound.aClientCity = cvContactCity.text;
clientDataFound.aClientPostalCode = cvPostalCode.text;
clientDataFound.aClientCellPhone = cvCellPhone.text;
clientDataFound.aClientPrimaryPhone = cvPrimaryPhone.text;
clientDataFound.aClientEMail = cvPersonalEmail.text;
clientDataFound.aClientNotes = cvNotes.text;
[localContext MR_saveNestedContexts];
[self reloadClientList];
}
}
-(void) reloadClientList {
//Init Array to hold TableView Data
tableDataArray = [NSMutableArray new];
[tableDataArray addObjectsFromArray:[ClientInfo findAll]]; // Load
[self.clientList reloadData];
}
这是 ClientInfo.m
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface ClientInfo : NSManagedObject
@property (nonatomic, retain) NSString * aClientAddr1;
@property (nonatomic, retain) NSString * aClientAddr2;
@property (nonatomic, retain) NSString * aClientCellPhone;
@property (nonatomic, retain) NSString * aClientCity;
@property (nonatomic, retain) NSString * aClientEMail;
@property (nonatomic, retain) NSData * aClientImage;
@property (nonatomic, retain) NSString * aClientName;
@property (nonatomic, retain) NSString * aClientNotes;
@property (nonatomic, retain) NSString * aClientPostalCode;
@property (nonatomic, retain) NSString * aClientPrimaryPhone;
@结尾