xml 解析器的单例问题。后导航
解析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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的方法
numberOfSectionsInTableView
中,您说您的表格视图只有一个部分。然后在cellForRowAtIndexPath
方法中,您对该部分进行切换。根据上面的代码,只应显示 name1,因为您的部分将始终为 0。In your method
numberOfSectionsInTableView
you say that your table view has only one section. Then in thecellForRowAtIndexPath
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.