Я вызываю веб-сервис в viewDidLoad
методе класса tableViewcontroller и анализирую данные в другом классе следующим образом
- (void)viewDidLoad {
[super viewDidLoad];
dataWebService = [[NSMutableData data] retain];
NSString *authString = [[[NSString stringWithFormat:@"%@:%@",@"admin", @"admin"] dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://172.16.3.47:8980/opennms/rest/alarms?limit=5"]] retain];
[request setValue:[NSString stringWithFormat:@"Basic %@",authString] forHTTPHeaderField:@"Authorization"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[dataWebService setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[dataWebService appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Eror during connection: %@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString* responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
AlarmWSParse* alarmParser = [[AlarmWSParse alloc]init];
severity = [alarmParser xmlParser:responseString];
NSLog(@"no of elements in array %d",[severity count]);
NSLog(@"Back to Alarm List View controller and severtiy array is %@",severity);
}
, а затем установить значение массива серьезности в ячейке таблицы как
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [severity count];
}
// Customize the appearance of table view cells.
- (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 = [severity objectAtIndex:indexPath.row];
NSLog(@"cellvalue %@",cellValue);
cell.textLabel.text = cellValue;
return cell;
}
Таблица остается пустой, но NSLog
правильно отображает все данные.
Кроме того, после вызова и анализа веб-службы мое приложение вылетает в симуляторе без сообщения об ошибке в отладчике.
Как отобразить эти значения в массиве в виде таблицы?
Угадайте, что ... сообщение nslog для cellValue или любого другого сообщения nslog, которое я включаю в tabelView:cellForRowAtIndexPath
, не выводится на консоль ..
Вот мой вид консоли
[Session started at 2011-12-22 11:12:07 +0530.]
2011-12-22 11:12:09.358 WebServiceTab[11815:207] do while loopalarm
2011-12-22 11:12:09.359 WebServiceTab[11815:207] severity is MAJOR
2011-12-22 11:12:09.359 WebServiceTab[11815:207] do while loopalarm
2011-12-22 11:12:09.359 WebServiceTab[11815:207] severity is MAJOR
2011-12-22 11:12:09.360 WebServiceTab[11815:207] do while loopalarm
2011-12-22 11:12:09.360 WebServiceTab[11815:207] severity is MAJOR
2011-12-22 11:12:09.360 WebServiceTab[11815:207] do while loopalarm
2011-12-22 11:12:09.360 WebServiceTab[11815:207] severity is MINOR
2011-12-22 11:12:09.361 WebServiceTab[11815:207] do while loopalarm
2011-12-22 11:12:09.361 WebServiceTab[11815:207] severity is MAJOR
2011-12-22 11:12:09.361 WebServiceTab[11815:207] no of elements in array 5
2011-12-22 11:12:09.362 WebServiceTab[11815:207] Back to Alarm List View controller and severtiy array is (
MAJOR,
MAJOR,
MAJOR,
MINOR,
MAJOR
)
Я разделяю несколько файлов исходного кода здесь: https://gist.github.com/fce50a3c4d20cb9c4677
Пожалуйста, посмотрите, если вы можете найти какие-либо ошибки. Мое приложение, похоже, было сделано только для сбоя: (