小编jon*_*jon的帖子

如何使用Core Data在Accessory示例中获取UITableViewCell

我有一个基于CoreDataBooks的应用程序.我想在iOS示例代码中提到的单元附件按钮中切换两个图像,但我遇到了障碍.我无法弄清楚如何获取在accessoryButtonTappedForRowWithIndexPath:方法中记录的UITableViewCell.该示例将对象存储在项目中作为键值,但我无法弄清楚如何使用我的患者和核心数据执行此操作.

首先,这是Accessory示例中的相关代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kCustomCellID = @"MyCellID";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [item objectForKey:@"text"];

    [item setObject:cell forKey:@"cell"];

    BOOL checked = [[item objectForKey:@"checked"] boolValue];
    UIImage *image = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
    button.frame = …
Run Code Online (Sandbox Code Playgroud)

iphone xcode core-data objective-c uitableview

1
推荐指数
1
解决办法
6378
查看次数

标签 统计

core-data ×1

iphone ×1

objective-c ×1

uitableview ×1

xcode ×1