Jon*_*nes 3 xcode objective-c uitableview ios5
我正在尝试更新我的UITableview,但是当我调用[tableView reloadData];表时不会更新,在我更改后滚动tableview上面的单元格名称.但它并没有添加新的行或类似的东西.
-(void)update {
[tableView reloadData];
NSLog(@" %i", [tableData count]);
}
Run Code Online (Sandbox Code Playgroud)
当我添加一行它返回2但是表没有更新时,nslog正在退回1.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
.
- (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"]];
Run Code Online (Sandbox Code Playgroud)
.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
Run Code Online (Sandbox Code Playgroud)
每次我看到这个问题都是因为UITableView插座没有连接.结果,reloadData呼叫被发送到nil.这几乎肯定是在这种情况下出了什么问题.这可以通过简单的日志语句轻松测试.
-(void)update {
NSLog(@"tableView is '%@'",tableView);
[tableView reloadData];
NSLog(@" %i", [tableData count]);
}
Run Code Online (Sandbox Code Playgroud)
你很可能会tableView is (null)在控制台中看到.
旁注:tableview填充的事实表明这些dataSource和delegate出口是连接的.
| 归档时间: |
|
| 查看次数: |
4956 次 |
| 最近记录: |