xml 解析器的单例问题。后导航

发布于 2024-09-27 13:33:44 字数 1692 浏览 0 评论 0原文

解析xml后。 xml 属性数据存储在 NSMutableArray *anArray 中;它位于 MyAppDelegate 中。我在 MyAppDelegate 中使用了 anArray。

对于我的 xml,我有一个根标签和 N 个子标签。

我的 xml 示例:

  <root>
    <child name1="",name2="",name3=""/>
    <child name1="",name2="",name3=""/>
    <child name1="",name2="",name3=""/>
    </root>

我完美地解析了数据,并在表视图上显示了 name1...... 当我导航时,它使用 didSelectRowAtIndexPath。我加载了 nib 文件。其中有表视图 IBOutlet。我为我的笔尖设置了类......数据源并将其委托给文件所有者,每件事都完美运行。导航功能完美运行...

现在我需要将数据加载到第二个 nib 文件表视图 name2 和 name3 值中。但它只显示 name2 值。该怎么办..我在我的控制器类中使用了上面的代码。用于第二个笔尖。

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 1;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
        return [appDelegate.anArray count]; 
    }

    - (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];
        }


        DetailsView *detailsview=[appDelegate.anArray objectAtIndex:indexPath.row];
        switch (indexPath.section) {
            case 0:
                cell.textLabel.text=detailsview.name1;
                break;
                case 1:
                cell.textLabel.text=detailsview.name2;
                    break;
                            default:
                break;
    }
    return cell;
    }

after parse xml. xml attributes data i stored in NSMutableArray *anArray; which is in MyAppDelegate. I used anArray in MyAppDelegate.

For my xml i do have One root Tag and N number Child tag.

my xml example:

  <root>
    <child name1="",name2="",name3=""/>
    <child name1="",name2="",name3=""/>
    <child name1="",name2="",name3=""/>
    </root>

i parsed data perfectly and i displayed name1 on table View.....
When i navigated it used didSelectRowAtIndexPath. And i loaded the nib file. which has tableview IBOutlet. i set class for my nib....datasource and delegate to the file owner every thing work perfectly. navigation stuff work perfectly....

now i need load data into second nib file tableview name2 and name3 values. but it displaying only name2 values. what to do .. I used the above code in my controller class. for second nib.

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 1;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
        return [appDelegate.anArray count]; 
    }

    - (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];
        }


        DetailsView *detailsview=[appDelegate.anArray objectAtIndex:indexPath.row];
        switch (indexPath.section) {
            case 0:
                cell.textLabel.text=detailsview.name1;
                break;
                case 1:
                cell.textLabel.text=detailsview.name2;
                    break;
                            default:
                break;
    }
    return cell;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘初心 2024-10-04 13:33:44

在您的方法 numberOfSectionsInTableView 中,您说您的表格视图只有一个部分。然后在 cellForRowAtIndexPath 方法中,您对该部分进行切换。根据上面的代码,只应显示 name1,因为您的部分将始终为 0。

In your method numberOfSectionsInTableView you say that your table view has only one section. Then in the cellForRowAtIndexPath method you do a switch on the section. Based on the code above, only name1 should be displayed, because your section will always be 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文