我是新手IOS并使用IB,我在UIViewController中工作UITableView,我在viewcontroller和setdelegate中实现了“UITableViewDelegate,UITableViewDataSource”,uitableview的数据源,但它不起作用,我不知道,
请帮我!
感谢您阅读这篇文章。
代码 viewcontroller.h
@interface ViewController : UIViewController<UITableViewDelegate,
UITableViewDataSource> @property (nonatomic, retain) IBOutlet UITableView *tableView;
代码视图控制器.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;
}