首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在执行编辑操作时启用表格视图单元格的编辑内容

如何在执行编辑操作时启用表格视图单元格的编辑内容
EN

Stack Overflow用户
提问于 2012-01-03 22:47:31
回答 1查看 725关注 0票数 0

大家好,祝大家新年快乐!

我有两个视图控制器,其中一个是用户填写表视图中的所有字段并单击保存,数据被插入到sqlite数据库的表中,我已经成功地从sqlite数据库表中插入、更新、检索数据。

用户可以查看保存的数据(我的案例:提醒)的另一个视图控制器.I已经成功显示了保存的数据,即,当我保存提醒时,将在视图提醒页面中添加一个单元格,并显示保存在实例中的提醒,类似于每个保存的提醒,依此类推。

用户将很有兴趣和需要编辑的内容,他/她saves.So我已经放置了一个编辑按钮,我已经实现了单元格的方向和删除,但我如何才能编辑单元格,即如何使单元格导航到添加提醒页面,其中的数据是保存的实例(提醒)的用户选择的单元格(在我的情况下:部分与单行)。

我可以让用户导航到添加提醒页面,但是如何访问表视图区中包含的对应于该提醒的值。

用户可以更改提醒,比如电话号码、日期、消息正文等。不管它到底是什么。

我做了几次尝试,在谷歌上搜索了各种链接,但都找不到合适有效的解决方案。

这是我如何根据用户在添加提醒页面中的保存来检索提醒:

代码语言:javascript
复制
-(void)loadgReminders
{
    self.frndsArray = nil;
    self.frndsArray = [[NSMutableArray alloc]init];

    //Retrieve the group of reminder
    const char *thePath = [self.databasePath UTF8String];
    sqlite3_stmt *statment;

    if (sqlite3_open(thePath, &remindersDB) == SQLITE_OK)
    {
    NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = 'Family'"];
        const char *sqlite_stmt = [getQuery UTF8String];

        if (sqlite3_prepare_v2(self.remindersDB, sqlite_stmt, -1, &statment, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(statment) == SQLITE_ROW) 
            {
                ReminderClass *remind = [[ReminderClass alloc]init];
                remind.Name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 1)];
                remind.Event = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 2)];
                remind.Date = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 3)];

                NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
                [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *date = [dateFormat dateFromString:remind.Date];
                [dateFormat setDateFormat:@"MMMM dd"];
                NSString *dateVal = [dateFormat stringFromDate:date];
                remind.Date = dateVal;

                [self.frndsArray addObject:remind];

                [remind release];
            }

            sqlite3_finalize(statment);
        }

        sqlite3_close(remindersDB);
    }
}

请给我提一些有价值的建议

提前感谢所有人:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 00:45:22

在您的表视图委托方法中:

代码语言:javascript
复制
 cellForRowAtIndexPath:  

您可以访问frndsArray的成员。类似地,当用户选择行时,

代码语言:javascript
复制
 didSelectRowAtIndexPath: 

在您的委托上调用。

只需访问frndsArray的同一成员(通常通过indexPath.row),并将此对象传递给细节/编辑viewController,无论是在它的初始化方法中,还是通过设置iVar。

如果要在细节视图控制器中实现保存操作,还需要将主键传递给细节VC,以便它可以基于该键执行sql更新。

编辑:伪代码:

代码语言:javascript
复制
 -(void) tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     ReminderClass *rem = (ReminderClass *)[self.frndsArray objectAtIndex:indexPath.row];

     // Instantiate your detail/editor view controller,
     // and pass in the ReminderClass object to be edited.
     ReminderDetailViewController *rdvc = [[ReminderDetailViewController alloc] initWithReminder: rem];
     [self.navigationController pushNavigationController:rdvc animated:YES];
     [rdvc release];
 }

编辑2:更多的psuedo代码(您还需要执行#import、@synthesize和dealloc )

在RminderDetailViewController.h中添加以下内容:

代码语言:javascript
复制
 @property(nonatomic, retain) ReminderClass *myLocalReminderInstance;

在RminderDetailViewController.m中,添加此初始化器方法:

代码语言:javascript
复制
 -(id) initWithReminder:(ReminderClass *)aReminder {
       if ( (self=[super init]) ) {
            self.myLocalReminderInstance = aReminder;
       }
       return self;
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8714000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档