-1

我有一个表格视图,它显示所有对象并且可以删除对象,现在我需要获取它,以便我可以从 NSMutableArray 编辑对象并保存和重新存储表格数据。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    AssignmentInfo *ai = [self.alist objectAtIndex:indexPath.row];
    UILabel *classname = (UILabel *)[cell viewWithTag:1];
    UILabel *assignementText = (UILabel *)[cell viewWithTag:2];
    UILabel *date = (UILabel *)[cell viewWithTag:3];

    classname.text = ai.className;
    assignementText.text = ai.assignmentTitle;
    date.text = ai.dateTimeString;
    // Configure the cell...

    return cell;
}

如果需要,这里是整个项目的链接:

http://www.abdelelrafa.com/AssignmentAppTwo.zip

4

2 回答 2

2

首先,将您的单元格拖动到情节提要中的 AddEditViewController(进行模态转场)。接下来选择segue并将其命名为“edit”。之后转到您的 AddEditViewController.h 并创建以下属性:

@property (nonatomic)BOOL edit;
@property (nonatomic,strong)AssignmentInfo *assignmentEditing;

之后,在您的 prepareForSegue 中的 AssignmentListViewController.m 中添加:

if ([segue.identifier isEqualToString:@"edit"]) {
    UITableViewCell *cell = sender;
    AddEditViewController *addEditController = segue.destinationViewController;
    [addEditController setOtherdelegate:self];
    addEditController.edit = YES;
    AssignmentInfo *a = [self.alist objectAtIndex:[self.tableView indexPathForCell:cell].row];
    addEditController.assignmentEditing = a;
    [self.alist removeObject:a];
}

最后在你的 AddEditViewController.m 中 viewDidLoad 添加:

if (self.edit) {
        self.className.text = self.assignmentEditing.className;
        self.assignmentTitle.text = self.assignmentEditing.assignmentTitle;
        self.assignmentDescription.text = self.assignmentEditing.assignmentDescription;
        NSString *string = self.assignmentEditing.dateTimeString;
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
        dateFormatter.timeStyle = NSDateFormatterShortStyle;
        dateFormatter.dateStyle = NSDateFormatterShortStyle;
        NSDate *date = [dateFormatter dateFromString:string];
        dateTimePicker.date = date;
}
于 2013-10-22T01:01:46.913 回答
-1

如果您不想要自定义动画,只需从您的对象中删除对象NSMutableArray并调用对象的reloadData方法UITableView

于 2013-10-21T23:42:18.300 回答