【发布时间】:2017-06-08 07:03:49
【问题描述】:
我有TableViewCell.xib 文件,其中每个单元格中可以有姓名、联系人等数据的摘要。现在,如果我触摸该单元格,它将转到另一个ViewController,其中将包含该单元格数据的详细信息。( ViewController 显示的内容无关紧要)。我想从这个 xib 文件的单元格触摸转到另一个 ViewController。我怎样才能做到这一点。
编辑:
CallHistoryTableViewCell.h
@interface CallHistoryTableViewCell : UITableViewCell
@property(nonatomic, strong) IBOutlet UILabel *contactName;
@property(nonatomic, strong) IBOutlet UILabel *contactNumber;
@end
这个类有 CallHistoryTableViewCell.xib 文件。
CallHistoryVC.h
@interface CallHistoryVC : UIViewController
@end
CallHistoryVC.m
#import "CallHistoryVC.h"
#import "CallHistoryTableViewCell.h"
@interface CallHistoryVC ()<UITableViewDelegate, UITableViewDataSource,CallingViewControllerDelegate> {
AppDelegate *appDelegate;
}
@property (nonatomic, strong) NSMutableArray<RecentCall> *sortedEventArray;
@property (weak, nonatomic) IBOutlet UITableView *tView;
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//---add one contact---//
[self defaultViewSetting];
_tView.delegate = self;
_tView.dataSource = self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 75;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _sortedEventArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CallHistoryTableViewCell";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailsOfHistory *storyViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"DetailsOfHistory"];
//[self presentViewController:storyViewController animated:YES completion:nil]; // present it
[self.navigationController pushViewController:storyViewController animated:YES];// or push it
NSLog(@"%ld",(long)indexPath.row);
}
一切正常,但在didSelectRowAtIndexPath indexPath 没有显示这意味着触摸不起作用。通过单击单元格,我想转到 stroyboard 中的另一个视图控制器。
【问题讨论】:
-
你读过 UITableView 文档吗?通过这个,developer.apple.com/documentation/uikit/uitableviewdelegate/…
-
实现UITableViewDelegate的didSelectRowAtIndexPath方法
-
问题是我无法将 xib 链接到 ViewController。是否可以将 xib 链接到情节提要中的 ViewController?
标签: ios objective-c xib