-1

我有一个 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;

@结尾

4

2 回答 2

1

我找到了...我的“clientList”没有连接到对象...不知道我怎么错过了那个!

于 2012-12-29T16:25:54.657 回答
0

我能想到的原因有几个:

  1. 您的表视图引用 clientList 为零。(未连接)
  2. 您的表视图的 DataSource & Delegate 未设置(实际上我不确定它是否在未设置 DataSource 时编译)
  3. 您的表视图是一个子类,UITableView并且在该子类中reloadData方法被覆盖。
于 2012-12-29T16:40:48.870 回答