Ios 以编程方式将tableview单元格设置为按钮
我已经成功地通过编程方式添加了tableview单元格,还使用works添加了一个搜索函数Ios 以编程方式将tableview单元格设置为按钮,ios,uitableview,button,cell,Ios,Uitableview,Button,Cell,我已经成功地通过编程方式添加了tableview单元格,还使用works添加了一个搜索函数 @interface Avfall () { NSMutableArray *totalStrings; NSMutableArray *filteredStrings; BOOL isFiltered; } @end @implementation Avfall - (id)initWithStyle:(UITableViewStyle)style { self = [
我希望我制作的单元格像按钮一样,你知道,当单元格右侧有一个箭头时,可以将你带到另一个视图 所以我的问题是:如何使单元格可单击,并以编程方式将它们连接到下一个视图(都连接到同一个视图)。我可以手动点击单元格并选择样式:基本、附件:显示指示器,然后用“推”键将其连接到下一个视图控制器,这样我就可以得到一个导航栏 我的代码: { 静态NSString*Cellidentifier=@“Cell”; UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:Cellidentifier]@interface Avfall () { NSMutableArray *totalStrings; NSMutableArray *filteredStrings; BOOL isFiltered; } @end @implementation Avfall - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.mySearchBar.delegate=self; self.myTableView.delegate=self; self.myTableView.dataSource=self; totalStrings=[[NSMutableArray alloc]initWithObjects:@"One", @"Two",@"Three", @"Four",nil]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if(searchText.length==0) { isFiltered=NO; } else { isFiltered=YES; filteredStrings=[[NSMutableArray alloc]init]; for (NSString *str in totalStrings) { NSRange stringRange=[str rangeOfString:searchText options:NSCaseInsensitiveSearch]; if(stringRange.location != NSNotFound) { [filteredStrings addObject:str]; } } } [self.myTableView reloadData]; } //table view datasource and delegate methods... -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(isFiltered) { return [filteredStrings count]; } return[totalStrings count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
您需要实现table view delegate didSelectRowAtIndexPath抱歉,但我不明白它们的意思:您已经实现了table view数据源,例如numberOfRowsInSection方法。数据源是相似的。尝试复制链接中提到的代码,尤其是清单6-1。我从BATTrailsViewController得到错误!这是什么?请在谷歌上搜索“uitableview示例”,并首先阅读它们的工作原理。如果你不理解这些概念,那么按照自己的方式进行黑客攻击是没有用的。我假设您并没有编写这段代码,而是从在线示例中复制、粘贴和测试了它?if(!单元格) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:Cellidentifier]; } 如果(!isFiltered) { cell.textlab.text=[totalStrings对象索引:indexath.row]; } 否则//它将被过滤 { cell.textlab.text=[filteredStrings objectAtIndex:indexath.row]; } 返回单元; } -(无效)搜索栏搜索按钮选中:(UISearchBar*)搜索栏 { [self.myTableView辞职第一响应者]; }