我通过手机上的WIFI连接到Mac上本地安装的webService。
我将四组数据加载到TableView中,每组都有不同的请求。完成第一次下载后,我将数据加载到TableView中并继续下面的下载。
当RestKit工作时,应用程序几乎已经死了。你几乎不能滚动TableView,必须等到下载过程完成才能工作。
如何在我的设备上使RestKit不那么沉重,以便我可以在工作时安静地下载数据?
编辑:
我在设备中运行以下消息时注意到:
warning: Unable to read symbols for /Users/david/Library/Developer/Xcode/iOS DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/info/dns.so (file not found).
warning: No copy of dns.so found locally, reading from memory on remote device. This may slow down the debug session.
我仍然想要了解其含义。
AppDelegate中。我初始化一个AEMEventosList并调用downloadEventos方法开始下载。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
//Original code
AEMMasterViewController *masterViewController = [[[AEMMasterViewController alloc] initWithNibName:@"AEMMasterViewController" bundle:nil] autorelease];
//Inicializar lista de eventos
AEMEventosList *aux = [[AEMEventosList alloc] init];
aux.delegate = masterViewController;
//Asignar la lista de eventos a la variable miembro de la clase
self.eventosList = aux;
[aux release];
// Comenzar la descarga de eventos desde el servidor
[self.eventosList downloadEventos];
//Orignal code
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
// self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.71 green:0.45 blue:0.05 alpha:1];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
AEMEventosList inti方法:
-(id)init {
self = [super init];
if (self) {
self.eventos = [NSMutableDictionary dictionary];
self.downloadingEventosGroupFlag = 0;
self.eventosGroupNames = [NSArray arrayWithObjects:
kEventosToday,
kEventosInAWeek,
kEventosInAMonth,
kEventosLaterThanAMonth,
nil];
//Iniciar el manager
self.manager = [RKObjectManager objectManagerWithBaseURL:kRestURL];
//Mapeo de atributos JSON a miembros de la clase AEMEvento
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[AEMEvento class]];
[mapping mapAttributes:
kIdEvento,
kNombreEvento,
kEntradilla,
kDescripcion,
kDiaDeInicio,
kDiaDeFin,
kHorarioTexto,
kIdFuente,
kNombreFuente,
kFotoURL,
kWebURL,
kUbicaciones,
kHorarios,
kDiaDeInicioYFinTexto,
nil];
//Especificar el mapeo de fechas
NSDateFormatter* dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:kDateFormatStringForJson];
[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]];
mapping.dateFormatters = [NSArray arrayWithObject:dateFormatter];
[dateFormatter release];
//Asignar el mapeo al manager siempre que se encuentre la clave "eventos" en el archivo JSON
[self.manager.mappingProvider setMapping:mapping forKeyPath:kEventos];
}
return self;
}
AEMEventosList downloadEventos方法
-(void)downloadEventos {
//Iniciar la descarga del grupo de eventos indicado por el atributo downloadingEventosGroupFlag
[self.manager loadObjectsAtResourcePath:[self.eventosGroupNames objectAtIndex:self.downloadingEventosGroupFlag] delegate:self];
//Enviar al delegado el mensaje de incio de descarga para que muestre la vista con el indicador de progreso.
[self.delegate AEMEventosListDidStartLoadingEventos:self];
}
表视图委派方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.eventosList.eventos count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.eventosList.eventos objectForKey:[self.eventosList.eventosGroupNames objectAtIndex:section]] count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
switch (section) {
case 0:
return NSLocalizedString(@"Today", @"Today's events tableview section title.");
break;
case 1:
return NSLocalizedString(@"In a week", @"In a week's events table view section title.");
break;
case 2:
return NSLocalizedString(@"In a month", @"In a month's events tableview section title.");
break;
case 3:
return NSLocalizedString(@"Later than a month" , @"Later than a month events tableview section title.");
break;
default:
return nil;
break;
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Obtener el evento de la lista para la celda
NSArray *aux = [self.eventosList.eventos objectForKey:[self.eventosList.eventosGroupNames objectAtIndex:indexPath.section]];
AEMEvento *auxEvento = [aux objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = [UIColor colorWithRed:0.2 green:0.3 blue:0.5 alpha:1];
cell.textLabel.font = [UIFont systemFontOfSize:13];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.textColor = [UIColor lightGrayColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:11];
cell.detailTextLabel.textAlignment = UITextAlignmentRight;
}
// Configure the cell.
cell.textLabel.text = auxEvento.nombreEvento;
cell.detailTextLabel.text = auxEvento.diaDeInicioYFinTexto;
NSString *path = [[NSBundle mainBundle] pathForResource:@"iconGijonBlanco" ofType:@"png"];
cell.imageView.image = [UIImage imageWithContentsOfFile:path];
return cell;
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
答案 0 :(得分:0)
您是否可以发布用于调用请求的代码以及用于处理请求的代码?没有看到这一点,听起来你正在实例化请求并在主线程上运行它们而不是使用异步并将请求传递给后台线程。
答案 1 :(得分:0)
RestKit与此问题无关。加载数据后,我有一个循环处理下载的每个元素(大约400次)。虽然模拟器可以每秒循环100次,但设备每秒只能处理4次。我必须搜索正在发生的事情,但我会打开一个新线程,因为这是一个与原始问题不同的问题。