我正在从 XML 文件中构建一个 NSMutableArray,并且需要返回 XML 文件中每个常驻 id 的计数。是否有可能做到这一点?
<residents>
<resident id="1">
<name>
<first>Daffy</first>
<last>Duck</last>
</name>
</resident>
<resident id="2">
<name>
<first>Mickey</first>
<last>Mouse</last>
</name>
</resident>
ETC...
我将使用与此类似的代码返回计数:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Count = %i", [appDelegate.residents count]);
return [appDelegate.residents count];
有什么建议么?
对于数组,在我的 AppDelegate.h 中我有:
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *residents;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *residents;
在 XMLAppDelegate.h 我使用:
@interface XMLAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *residents;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *residents;
@end