Jay*_*nyi 0 iphone core-data objective-c ios5
我尝试从核心数据填充我的表,并在此行给出错误
Tips *tipy = [arr objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)
这是我的.m文件
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Tips *tipy = [arr objectAtIndex:indexPath.row];
cell.textLabel.text = [tipy tipdescription];
cell.detailTextLabel.text = [tipy.tipnumber stringValue];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
app和arr在.h文件中声明,并在.m文件中合成
@property (nonatomic, retain) AppDelegate *app;
@property(nonatomic, assign) NSArray *arr;
Run Code Online (Sandbox Code Playgroud)
正如moxy所说,你应该写self.arr而不是arr.你有设置@property(nonatomic, assaign) NSArray *arr;你是否合成了这些属性?一定要这样做.并尝试@property(nonatomic, retain) NSArray *arr;而不是@property(nonatomic, assaign) NSArray *arr;.该组合不会增加保留计数,因此该值有可能被自动释放.不要忘记在dealloc中释放arr以避免内存泄漏.