UITableView(二)
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSArray *list = @[@"条目1",@"条目2"]; self._dataList = list; UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain]; self._tableView = table; self._tableView.dataSource = self; self._tableView.delegate = self; [self.view addSubview:self._tableView]; NSOperationQueue *queue=[[NSOperationQueue alloc]init]; self._queue = queue; } #pragma mark - Table view data source - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if(cell == nil){ //cell的四种样式: //UITableViewCellStyleDefault, // 默认风格,自带标题和一个图片视图,图片在左 //UITableViewCellStyleValue1, // 只有标题和副标题 副标题在右边 //UITableViewCellStyleValue2, // 只有标题和副标题,副标题在左边标题的下边 //UITableViewCellStyleSubtitle // 自带图片视图和主副标题,主副标题都在左边,副标题在下 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; } NSString *url = @"http://XXXXX.com/article/uploadfile/2014/0905/20140905042806503.jpg"; NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; UIImage *image = [UIImage imageWithData:data]; dispatch_async(dispatch_get_main_queue(), ^{ printf("height = %f\r", image.size.height); printf("width = %f\r", image.size.width); cell.imageView.image = image; }); }]; [self._queue addOperation:operation]; cell.imageView.image = [UIImage imageNamed:@"default.jpg"]; cell.textLabel.text = [self._dataList objectAtIndex:[indexPath row]]; cell.detailTextLabel.text = @"详细信息"; return cell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self._dataList count]; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *value = [__dataList objectAtIndex:[indexPath row]]; printf("value = %s", [value UTF8String]); } @end
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)