У меня есть синтаксический анализатор NSXML, который хочет извлечь данные и поместить их в массив NSMutable. Он работает, когда я NSLog массива. Но когда я отображаю массив в виде таблицы, он терпит неудачу. Хорошо, если я могу уточнить, какая ошибка, которая у меня есть, потому что при запуске нет ошибки.IOS Как отобразить NSXMLparser с массивом NSMutable в tableview?
Это мой ViewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
// output = [[NSMutableArray alloc]initWithObjects:@"red",@"green", nil];
NSLog(@"Response recieved");
output= [[NSMutableArray alloc] init];
feeds = [[NSMutableArray alloc] init];
// NSString *severity = @"Informational";
NSString *soapMessage = @"<?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>"
" <IncidentGetList xmlns=\"https://www.monitoredsecurity.com/\">"
"<Severity></Severity>"
"<SourceOrganization></SourceOrganization>"
"<DestinationOrganization></DestinationOrganization>"
"<MaxIncidents></MaxIncidents>"
"<SourceIP></SourceIP>"
"<Category></Category>"
"<ExcludeCategory></ExcludeCategory>"
"<StartTimeStampGMT></StartTimeStampGMT>"
"<EndTimeStampGMT></EndTimeStampGMT>"
"<CustomerSeverity></CustomerSeverity>"
"</IncidentGetList>"
"</soap:Body>"
"</soap:Envelope>";
NSURL *url = [NSURL URLWithString:@"https://api.monitoredsecurity.com/SWS/incidents.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"https://www.monitoredsecurity.com/IncidentGetList" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
[connection start];
if(connection)
{
webResponseData = [NSMutableData data] ;
}
else
{
NSLog(@"Connection is NULL");
}
}
This is my NSXMLparser
//Implement the NSXmlParserDelegate methods
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict
{
element = elementName;
if ([element isEqualToString:@"SecurityIncidentSummary"]) {
IncidentGetList = [[NSMutableDictionary alloc] init];
Severity = [[NSMutableString alloc] init];
} //NSLog(@"current element: ", elementName);
}
- (void)parserDidStartDocument:(NSXMLParser *)parser{
NSLog(@"File found and parsing started");
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([element isEqualToString:@"Severity"]) {
[Severity appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"SecurityIncidentSummary"]) {
[IncidentGetList setObject:Severity forKey:@"Severity"];
[feeds addObject:[IncidentGetList copy]];
}
[self.datalist reloadData];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@"Final Feed : %@",feeds);
//[self.datalist reloadData];
}
Это мой TableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
return [feeds count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"UITableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if(cell == nil){
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textLabel.text= [[feeds objectAtIndex:indexPath.row]objectForKey:@"Severity"];
//cell.textLabel.text= output[indexPath.row];
return cell;
}
Вы назначены источник данных вашей точки зрения табличной? вы подключили розетку настольного вида? – Kreiri
запишите этот «cell.textLabel.text» и посмотрите, что он показывает? – Jamil
Да, я назначил источник данных и подключился к IBoutlet. – zac