我有一个通过解析 xml 文件填充的UITableView
用途。NSMutableArray
问题:数据被添加到数组中,但在UITableView
.
子列表.h
@interface SubList:UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *List1;
NSXMLParser *xmlparser;
NSURLConnection *conn;
NSMutableData *webdata;
NSString *FolderID;
NSMutableArray *info;
NSMutableArray *SubFolderData;
}
@property(nonatomic,retain) NSMutableArray *info;
@property(nonatomic,retain) NSMutableArray *SubFolderData;
@property (nonatomic,retain)NSString *FolderID;
@property(nonatomic,weak)IBOutlet UITableView *List1;
@property (nonatomic,retain) NSString *theXML;
@结尾
子列表.m
@implementation SubList
- (void)viewDidLoad
{
self.navigationController.navigationBar.hidden=YES;
[super viewDidLoad];
[self initWithData];
[self GetChilds:FolderID UserID:@"1"];
}
-(void)GetChilds:(NSString*)FolderIDRecvd UserID:(NSString*)userID
{
FolderID=[NSString stringWithFormat:@"%@", FolderIDRecvd];
NSString *_UserID=@"1";
NSString *soapMsg=[NSString stringWithFormat:@"<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><TreeDataSubFolder xmlns='http://tempuri.org/'><FolderID>%@</FolderID><UserId>%@</UserId></TreeDataSubFolder></soap:Body></soap:Envelope>",FolderID,_UserID];
NSURL *url=[NSURL URLWithString:@"http://192.168.1.5/interlogicsmobile/interlogics.asmx?op=TreeDataSubFolder"];
xmlparser = [[NSXMLParser alloc] initWithContentsOfURL:url];
NSMutableURLRequest *req=[NSMutableURLRequest requestWithURL:url];
NSString *msgLength=[NSString stringWithFormat:@"%d",[soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/TreeDataSubFolder" forHTTPHeaderField:@"SOAPAction"];
[req addValue:@"length" forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn=[[NSURLConnection alloc]initWithRequest:req delegate:self];
if(conn) {
webdata=[[NSMutableData data] retain];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
int responseStausCode = [httpResponse statusCode];
[webdata setLength: 0];
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data
{
[webdata appendData:data];
}
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error
{
[webdata release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
theXML= [[NSString alloc]
initWithBytes: [webdata mutableBytes]
length:[webdata length]
encoding:NSUTF8StringEncoding];
[theXML release];
SubListParser *parserObjForData1=[[SubListParser alloc]init];
SubFolderData=[[[NSMutableArray alloc]init]retain];
SubFolderData=[parserObjForData1 UserXMLParser1:webdata];
[connection release];
[webdata release];
[List1 reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return([SubFolderData count]/2);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row]*2;
static NSString *cellIdentifier=@"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
cell.textLabel.text = [SubFolderData objectAtIndex:row+1];
cell.detailTextLabel.text = [SubFolderData objectAtIndex:row];
}
for (int i=0; i<=[SubFolderData count]; i++) {
NSString *filename = [SubFolderData objectAtIndex:indexPath.row];
NSString *ext = [filename pathExtension];
if ([ext isEqualToString:@"doc"] || [ext isEqualToString:@"DOC"]) {
[cell.imageView setImage:[UIImage imageNamed:@"DOC.png"]];
} else if ([ext isEqualToString:@"jpg"]|| [ext isEqualToString:@"JPG"]) {
[cell.imageView setImage:[UIImage imageNamed:@"JPG.png"]];
}else if([ext isEqualToString:@"pdf"]|| [ext isEqualToString:@"PDF"]){
[cell.imageView setImage:[UIImage imageNamed:@"PDF.png"]];
}else if([ext isEqualToString:@""]){
[cell.imageView setImage:[UIImage imageNamed:@"Folder2.png"]];
}else if([ext isEqualToString:@"docx"]|| [ext isEqualToString:@"DOCX"]){
[cell.imageView setImage:[UIImage imageNamed:@"DOCX.png"]];
}else if([ext isEqualToString:@"TIF"]|| [ext isEqualToString:@"tif"]){
[cell.imageView setImage:[UIImage imageNamed:@"TIFF.png"]];
}else if([ext isEqualToString:@"png"]|| [ext isEqualToString:@"PNG"]){
[cell.imageView setImage:[UIImage imageNamed:@"PNG.png"]];
}else if([ext isEqualToString:@"gif"]|| [ext isEqualToString:@"GIF"]){
[cell.imageView setImage:[UIImage imageNamed:@"GIF.png"]];
}else if([ext isEqualToString:@"jpeg"]|| [ext isEqualToString:@"JPEG"]){
[cell.imageView setImage:[UIImage imageNamed:@"JPG.png"]];
}
}
return cell;
}
@end
编辑
-(NSMutableArray *)UserXMLParser1:(NSData *)WebDataRecieved1
{
NSXMLParser *xmlparser1=[[NSXMLParser alloc]initWithData:WebDataRecieved1];
[xmlparser1 setDelegate:self];
BOOL success=[xmlparser1 parse];
NSLog(@"%i",success); return listset1;
}