我試圖更新我的UITableview,但是當我打電話給[tableView reloadData];
時,表格並沒有更新,之後我將tableview在單元格名稱上方滾動,同時被更改。但它不是增加一個新的行或類似的東西。reloadData不起作用
-(void)update {
[tableView reloadData];
NSLog(@" %i", [tableData count]);
}
當我添加一行它返回2,但表不更新。
- (void) refresh:(id)sender {
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl]
encoding:NSUTF8StringEncoding
error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:[results objectForKey:@"items"]];
[self performSelector:@selector(update) withObject:nil afterDelay:.2];
}
。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Change UITableViewCellStyle
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
NSDictionary *item = [tableData objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[item objectForKey:@"title"]];
[[cell detailTextLabel] setText:[item objectForKey:@"descript"]];
[[cell detailTextLabel] setText:[item objectForKey:@"detail"]];
。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
'[self setTableData:]'做了什麼,'cellForRowAtIndexPath:'方法是怎麼樣的? – Eimantas 2012-04-17 19:06:16
[self setTableData:]正在設置cellforrowathindexpath中的數據(detailtext,image,title) – Jones 2012-04-17 19:14:15
@Eimantas我編輯了消息!與cellForRowAtIndexPath: – Jones 2012-04-17 19:15:55