1

我在 xcode 3 中很新,我真的需要帮助

我使用 UITableView 和 XML 开发了我的应用程序来显示内容。

我有 3 个 .xib 文件,它们分别是 rootViewController、SecondViewController 和 mainview。

所以问题是: 当我尝试在 rootViewController 中执行 didSelectrow 并访问 SecondViewController 中的 NSMutableArray *array 并在推送动画之前用 rootViewController 中的新数组值替换 *array 值时。

我的 SecondViewController 上的数组值第一次更改,但是当我按下后退按钮并选择另一行时,我的 SecondViewController 数组保持读取前一个数组而不是更改为新数组。我尝试初始化但没有运气

这是我在 rootViewController UITableview (didSelectRow) 上的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if(2ndController == nil)

2ndController = [[DetailViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];

    //Declare xml NSMutable array record
    ListRecord *record = [self.entries objectAtIndex:indexPath.row];

    //access SecondViewController NSMutable *record
    2ndController.record = [[[NSMutableArray alloc] init] autorelease];   

        //inserting the value from firstview to secondview before push
    2ndController.record = record;



    //push animation
    [self.navigationController pushViewController:2ndController animated:YES];



}

这是我的第二个视图控制器:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    switch(indexPath.section)
    {
        case 0:

            [cell setText:record.name];
            break;
        case 1:

            [cell setText:record.Age];
            break;
        case 2:
        [cell setText:record.summary];
            break;
    }

    return cell;
}

希望可以有人帮帮我..

提前致谢.....

4

2 回答 2

4

一些事情,

你做,

2ndController.record = [[[NSMutableArray alloc] init] autorelease];

并跟进

[cell setText:record.name];

显然,该record属性似乎不是一个实例,NSMutableArray所以我认为数组初始化部分与您所做的一样不正确,并且已经提到,

2ndController.record = record;

但我认为问题是你保留了你的UITableViewController子类。您是否尝试过重新加载数据?

[self.tableView reloadData];

将其添加到viewWillAppear您的DetailViewController.

于 2011-07-01T01:24:54.087 回答
1

您应该再次查看这两行:

2ndController.record = [[[NSMutableArray alloc] init] autorelease];   

//inserting the value from firstview to secondview before push
2ndController.record = record;

第一行对您没有任何用处。它创建并初始化一个新的 NSMutableArray 并将记录属性设置为该新数组。

但是在下一行中,您再次将相同的“记录”属性设置为不同的对象,因此不再引用第一行中的数组。因此,您可能还没有创建它。

这完全不是你的问题,但这个评论太大了,无法评论。:)

于 2011-07-01T00:36:51.293 回答