【发布时间】:2011-03-12 18:16:39
【问题描述】:
我在表格视图中加载数据时遇到问题。当视图加载时,我看到了表格,但单元格中没有填充任何内容。
PMs.h
@interface Pms : TTTableViewController {
NSArray *rows;
TTTableSubtitleItem *item;
}
@property (retain,nonatomic) NSArray *rows;
PMs.m
- (void)dealloc {
[rows release];
[super dealloc];
}
- (id)init {
//[self.navigationController setNavigationBarHidden:NO];
if (self = [super init]) {
self.variableHeightRows = YES;
self.dataSource = nil;
}
return self;
}
-(void)getLatest{
NSURL *url = [NSURL URLWithString:@"http://URL.com/pms.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
NSMutableArray *zodiaq = (NSMutableArray *)[[dict objectForKey:@"users"] retain];
TTListDataSource* tableItems = [[[TTListDataSource alloc] init] autorelease];
for(NSDictionary *dict in zodiaq){
item = [TTTableSubtitleItem itemWithText:[dict objectForKey:@"from_user"] subtitle:[dict objectForKey:@"subject"]
imageURL:nil
defaultImage:nil
URL:@"tt://tableItemTest"
accessoryURL:nil];
[tableItems.items addObject:item];
}
self.dataSource = [TTListDataSource
dataSourceWithItems:tableItems.items];
[jsonreturn release];
}
- (void)loadView {
[super loadView];
[self setTableViewStyle:UITableViewStylePlain];
self.tableView.frame = CGRectMake(0, 44, 320, 396);
[self getLatest];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
@end
当我这样做时
NSLog(@"Data: %@",[dict objectForKey:@"subject"]);
if 显示正在检索的所有主题行,但不填充表格。
【问题讨论】:
标签: objective-c json three20