【发布时间】:2012-08-21 14:20:53
【问题描述】:
我是新手 IOS 并使用 IB,我在 UIViewController 中工作 UITableView,我在 viewcontroller 和 setdelegate 中实现了“UITableViewDelegate,UITableViewDataSource”,uitableview 的数据源,但它不起作用,我不知道,
请帮帮我!
感谢您阅读本文。
代码 viewcontroller.h
@interface ViewController : UIViewController<UITableViewDelegate,
UITableViewDataSource> @property (nonatomic, retain) IBOutlet UITableView *tableView;
代码 viewcontroller.m
- (void)viewDidLoad { [tableView setDataSource:self];
[tableView setDelegate:self];
dispatch_async(htvque, ^{
NSData* data = [NSData dataWithContentsOfURL: listFilmByCate];
NSError* error;
jsonTable = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
listDataTable = [jsonTable objectForKey:@"List"];
dispatch_async(dispatch_get_main_queue(), ^{
[tableView reloadData];
});
});
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return listDataTable.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dataTable = [listDataTable objectAtIndex:indexPath.row];
NSData *receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[dataTable objectForKey:@"Thumbnail"]objectForKey:@"Url1"]]]; UIImage *image = [[[UIImage alloc] initWithData:receivedData] stretchableImageWithLeftCapWidth:50 topCapHeight:80];
static NSString *simple_cell = @"simpleCell";
CustomizeCell_Home *customize_cell = (CustomizeCell_Home *)[tableView dequeueReusableCellWithIdentifier:simple_cell];
if (simple_cell == nil)
{}
customize_cell.imageView.image = image;
customize_cell.lbldescription.text =[dataTable objectForKey:@"LongDescription"];
customize_cell.lblTitle.text = [dataTable objectForKey:@"VName"];
customize_cell.lblTitle.lineBreakMode = UILineBreakModeWordWrap | UILineBreakModeTailTruncation;
customize_cell.lbldescription.lineBreakMode = UILineBreakModeWordWrap | UILineBreakModeTailTruncation;
customize_cell.lbldescription.numberOfLines=4;
customize_cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgtblRight.png"]];
return customize_cell;
}
【问题讨论】:
-
嗨 CBredlow,我想在 uiviewcontroller 中显示 uitableview?我为它设置了委托和数据源,但不起作用
标签: ios json uitableview uiviewcontroller storyboard