tableview简单例子和简单遍历
Instruction_set_list.h
#import <UIKit/UIKit.h> @interface Instruction_set_list : UIViewController @property (strong,nonatomic)UITableView *tableviewInstruction; @property(nonatomic,strong)NSArray *rightArr; @end
#import "Instruction_set_list.h" #import "File_list.h" #define fDeviceWidth ([UIScreen mainScreen].bounds.size.width) #define fDeviceHeight ([UIScreen mainScreen].bounds.size.height) @interface Instruction_set_list ()<UITableViewDataSource,UITableViewDelegate> @end @implementation Instruction_set_list - (void)viewDidLoad { [super viewDidLoad]; // 创建tableview [self setTableView]; // 下拉刷新 [self setupRefresh]; } // 下拉刷新 - (void)setupRefresh { NSLog(@"setupRefresh -- 下拉刷新"); UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(refreshClick:) forControlEvents:UIControlEventValueChanged]; refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"拼命刷新中!"]; //刷新图形时的颜色,即刷新的时候那个菊花的颜色 refreshControl.tintColor = [UIColor redColor]; [self.tableviewInstruction addSubview:refreshControl]; [refreshControl beginRefreshing]; [self refreshClick:refreshControl]; } // 下拉刷新触发,在此获取数据 - (void)refreshClick:(UIRefreshControl *)refreshControl { // [self.rightArr removeAllObjects];//清除旧数据,每次都加载最新的数据 // [refreshControl endRefreshing]; [self.tableviewInstruction reloadData];// 刷新tableView即可 } #pragma mark -创建tableview -(void)setTableView{ _tableviewInstruction = [[UITableView alloc]initWithFrame:CGRectMake(0,0,fDeviceWidth,fDeviceHeight) style:UITableViewStylePlain]; _tableviewInstruction.delegate =self;//写了这两句话哟调用delegate*/ _tableviewInstruction.dataSource=self; [self.view addSubview:_tableviewInstruction]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.rightArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID=@"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if(cell==nil){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } // cell.textLabel.text=[NSString stringWithFormat:@"至爱小播指令集-----------------%zd",indexPath.row]; if (indexPath.row==0) { cell.textLabel.text = @"666"; } cell.textLabel.text = self.rightArr[indexPath.row]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头 return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { File_list *ShowViewController=[[File_list alloc]init]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSLog(@"%ld",(long)indexPath.row); NSLog(@"%@",cell.textLabel.text); ShowViewController.navigationItem.title=cell.textLabel.text; [self.navigationController pushViewController:ShowViewController animated:NO]; } @end
简单的遍历:
for (TGCurrencyInlist *obj in arr) { [self.popUpButton_First addItemWithTitle:obj.ccy_code]; } for (int i = 0; i < arr.count; i++) { TGCurrencyInlist *rowInlist = arr[i]; [self.popUpButton_First addItemWithTitle:rowInlist.ccy_code]; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix