我有一个小应用程序,我正在尝试从sqlite数据库加载UITableView中的一些数据。显然一切正常,但当我尝试滚动时,我得到Null数据。
我的代码:
self.tblContacts.dataSource = self;
self.tblContacts.delegate = self;
self->mainManager = [[MainManager alloc] init: [NSString stringWithFormat:@"%@/contacts.db", resourcePath]];
self->contactList = [[ContactManager alloc] init];
self->contactList = [mainManager loadContacts];
-----------------------------------------------------
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self->contactList getContactsCount];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellID = @"Cell";
CustomCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (!Cell)
Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
Cell.lblCompany.text = [[self->contactList getContact:indexPath.row] company];
Cell.lblContact.text = [NSString stringWithFormat:@"%@ %@", [[self->contactList getContact:indexPath.row] name], [[self->contactList getContact:indexPath.row] surname]];
return Cell;
}
截图:
如果有人可以赐教我。提前谢谢。
最好的问候。
答案 0 :(得分:3)
我解决了。我是Objective-c中的菜鸟,我需要更多地了解(强,弱,保留,分配)。我只是在我的联系人类中用保留替换弱:
@property (retain) NSString *name;
@property (retain) NSString *surname;
@property (retain) NSString *company;
@property (retain) NSString *cif;
@property (retain) NSString *email;
@property (retain) NSString *address;
@property (retain) NSString *city;
@property (retain) NSString *telephone;
@property (retain) NSString *provider;
strong =保留:
<强>弱强>:
来源: Objective-C ARC: strong vs retain and weak vs assign
现在完美无缺!
非常感谢,问候。
答案 1 :(得分:0)
试试这个,
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellID = @"Cell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *) currentObject;
break;
}
}
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Cell.lblCompany.text = [[self->contactList getContact:indexPath.row] company];
Cell.lblContact.text = [NSString stringWithFormat:@"%@ %@", [[self->contactList getContact:indexPath.row] name], [[self->contactList getContact:indexPath.row] surname]];
return Cell;
}