我正在使用自定义UITableView
,其中我传递了2个数组(图像和名称)数组显示在UITableView
上。现在我想当我点击表格的任何单元格时,将显示UITableViewCell
的凭证,以显示在下一个视图中,其中我使用UIImageView
(用于图像)和UILabel(用于名称显示)。我还输入了我必须显示图像和名称的VC。 请建议我的代码到另一个视图中显示的名称和形象IOS:在我的项目中浏览tableView并在下一个视图中显示表格视图数据
我使用如下代码
.h文件中
#import <UIKit/UIKit.h>
@interface FriendsViewController : UIViewController<UISearchDisplayDelegate , UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
{
UITableView *friendslisttable;
NSMutableArray *friendslist;
NSMutableArray *friendsnamearray;
NSMutableArray *profilepicarray;
UIImageView * frndprofpic;
UILabel *friendnamelabel;
NSArray *searchResults;
}
@end
.m文件
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Friends";
friendslisttable = [[UITableView alloc]initWithFrame:CGRectMake(0,110 , self.view.frame.size.width, self.view.frame.size.height)] ;
friendslisttable.delegate = self;
friendslisttable. dataSource = self;
[self.view addSubview:friendslisttable];
friendsnamearray = [[NSMutableArray alloc]initWithObjects:@"friend1",@"friend12",@"friend13",@"friend14",@"friend15",@"friend16",@"friend17",@"friend18",@"friend19",@"friend20",@"friend21 ",@"friend22",@"", nil];
profilepicarray = [[NSMutableArray alloc]initWithObjects:@"download3.jpeg", @"12045540_717548405011935_7183980263974928829_o.jpg" , @"download4.jpeg", @"download5.jpeg", @"download6.jpg", @"download12.jpeg", @"download13.jpeg", @"download16.jpeg",@"download3.jpeg", @"download6.jpg", @"download12.jpeg", @"download16.jpeg", @" ", nil];
}
#pragma mark - TableView Delegate Method -------------------->>>>
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return searchResults.count;
}
else {
return friendsnamearray.count;
}
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellidentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier ];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidentifier];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
friendslisttable = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
friendslisttable = [searchResults objectAtIndex:indexPath.row];
} else
{
friendslisttable = [friendsnamearray objectAtIndex:indexPath.row];
}
frndprofpic = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 50, 50)];
frndprofpic.image=[UIImage imageNamed:[profilepicarray objectAtIndex:indexPath.row]];
[cell.contentView addSubview:frndprofpic];
friendnamelabel = [[UILabel alloc]initWithFrame:CGRectMake(70, 10, 250, 50)];
friendnamelabel.text = [friendsnamearray objectAtIndex:indexPath.row];
friendnamelabel.font = [UIFont fontWithName:@"ChalkboardSE-Regular" size:20];
[cell.contentView addSubview:friendnamelabel];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!indexPath.row) {
ProfileViewController *u = [[ProfileViewController alloc]init];
[self.navigationController pushViewController:u animated:YES];
}
}
检查此... http://stackoverflow.com/questions/22759167/how-to-make-a-push-segue-when-a-uitableviewcell-is-selected –
我使用自定义tableview请告诉我在didSelectRow方法中做了什么更改 –