Я обращаюсь к веб-службе, где я даю дату начала и дату окончания, и взамен я получаю строковый массив из веб-службы. Каждая строка из массива строк находится в этом формате «1 | Название банка | Учетная запись NO | 121 | Название ящика». теперь я хочу отобразить это содержимое в первой строке таблицы. Вторая строка должна быть занята второй строкой массива String. Я попытался в следующем порядке, но мой стол кажется пустым. Пожалуйста, помогите.отображение содержимого массива в виде таблицы
#import "RootViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
recordResults = FALSE;
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<S:Header/\>\n"
"<S:Body>\n"
"<ns2:reviewDeposit xmlns:ns2=\"http://services.cbp.syntel.org/\">\n"
"<FromDate>%@</FromDate>\n"
"<ToDate>%@</ToDate>\n"
"</ns2:reviewDeposit>\n"
"</S:Body>\n"
"</S:Envelope>\n", @"Sep 10, 2009", @"Dec 10, 2009"
];
.........bla bla
}
/*.....methods for accessing web service*/
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict{
if([elementName isEqualToString:@"return"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
recordResults = TRUE;
}}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(recordResults)
{
//DFSSoapTestAppDelegate *appdel=(DFSSoapTestAppDelegate *)[[UIApplication sharedApplication]delegate];
[soapResults appendString: string];
}}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if([elementName isEqualToString:@"return"])
{
recordResults = FALSE;
//chunks=[soapResults componentsSeparatedByString:@"|"];
//NSString *s=[chunks objectAtIndex:0];
if([soapResults isEqualToString:@"Error"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry Please Refine Your Search"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
[email protected]"";
[email protected]"";
}else {
[chunks addObject:soapResults];//where chunks is a NSMutable array
NSLog(@"The Soap Results are.....");
NSLog(soapResults);// "1|Bank Name|Account NO|121|Drawer Name"
}
}
/
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return [chunks count];}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSString *cellValue=[chunks objectAtIndex:indexPath.row];
cell.text =cellValue;
return cell;
}
- (void)dealloc {
[super dealloc];
}
@end
Я пробовал это, но приложение вылетает. без ошибок в консоли – shreedevi
Добавьте некоторые точки останова в свой код, в частности, в методы делегата UITableView и в reloadData. Пройдите через свой код и посмотрите, можете ли вы найти источник сбоя. Наконец, после того, как вы узнаете, где искать переменные с неправильными значениями. –