서버에서 콘텐츠를로드하는 UITableView가 있습니다. 모두 잘 작동하고 내용이 올바르게로드되지만 UITableView를 스크롤하면 약간 지연됩니다. 서버에서 콘텐츠를 다운로드하는 메서드를 만들고이 메서드를 내 viewDidLoad 메서드에서 호출합니다.이 메서드는 앱을 열 때 가장 먼저 열리기 때문에이 메서드를 호출합니다. 이 방법이 최선의 방법인지 잘 모르겠습니다. 어떻게 피할 수 있습니까? 여기 내 코드는 다음과 같습니다.UITableView Scroll Lag
- (void)viewDidLoad
{
[super viewDidLoad];
// Method that Loads the Content
[self retrieveData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Retorna o número de linhas pelo array de programacao.
return programacaoArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// ALTURA da TableViewCell
return 150;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"CellIdentifier";
ProgramacaoTableCell *cell = (ProgramacaoTableCell *)[self.tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[ProgramacaoTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
// Configure the Cell
Programacao *programacaoObject;
programacaoObject = [programacaoArray objectAtIndex:indexPath.row];
cell.atracaoImagem.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:programacaoObject.programacaoImagem]]];
cell.nomeLabel.text = programacaoObject.programacaoNome;
cell.dataLabel.text = programacaoObject.programacaoData;
cell.localLabel.text = programacaoObject.programacaoLocal;
return cell;
}
- (void) retrieveData
{
NSURL *url = [NSURL URLWithString:getDataURL];
NSData *data = [NSData dataWithContentsOfURL:url];
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
// SETUP programacaoArray
programacaoArray = [[NSMutableArray alloc] init];
// Loop throught do Array
for (int i = 0; i < jsonArray.count; i++) {
// Cria o PROGRAMACAO Objeto
NSString *pID = [[jsonArray objectAtIndex:i] objectForKey:@"id"];
NSString *pNome = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoNome"];
NSString *pImagem = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoImagem"];
NSString *pDescricao = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoDescricao"];
NSString *pData = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoData"];
NSString *pLocal = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoLocal"];
NSString *pPrecos = [[jsonArray objectAtIndex:i] objectForKey:@"programacaoPrecos"];
// Add to the Array
[programacaoArray addObject:[[Programacao alloc] initWithNome:pNome andImagem:pImagem andDescricao:pDescricao andData:pData andLocal:pLocal andPrecos:pPrecos andID:pID]];
}
// RELOAD TABLE VIEW
[self.tableView reloadData];
}
이'programacaoObject.programacaoImagem' 문자열의 유형을 포함 않습니다 로딩 이미지를 사용할 수 있습니까? 그것은 'http : //'링크입니까? – Michael
그는 질문에서 그가 서버에서 콘텐츠를 다운로드한다고 말하면 내 추측은 '예'라고합니다. –
그리고이 '예'또한 질문의 답이 될 것입니다;) – Michael